jscheffl commented on code in PR #43215:
URL: https://github.com/apache/airflow/pull/43215#discussion_r1810696885
##########
providers/src/airflow/providers/edge/executors/edge_executor.py:
##########
@@ -86,9 +88,30 @@ def execute_async(
)
)
- @provide_session
- def sync(self, session: Session = NEW_SESSION) -> None:
- """Sync will get called periodically by the heartbeat method."""
+ def _check_worker_liveness(self, session: Session) -> bool:
+ """Reset worker state if heartbeat timed out."""
+ changed = False
+ heartbeat_interval: int = conf.getint("edge", "heartbeat_interval")
+ lifeless_workers: list[EdgeWorkerModel] = (
+ session.query(EdgeWorkerModel)
+ .filter(
+ EdgeWorkerModel.state != EdgeWorkerState.UNKNOWN
+ and EdgeWorkerModel.last_update
+ < (timezone.utcnow() - timedelta(seconds=heartbeat_interval *
5))
+ )
+ .all()
+ )
+
+ for worker in lifeless_workers:
+ changed = True
+ worker.state = EdgeWorkerState.UNKNOWN
+ session.add(worker)
Review Comment:
I believe from ORM model this is not correct. You don't want to ADD a new
worker record but just want to update. In this case you just need to `commit()`
on the session to write changes back to DB.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]