jscheffl commented on code in PR #43215:
URL: https://github.com/apache/airflow/pull/43215#discussion_r1808866814


##########
providers/src/airflow/providers/edge/executors/edge_executor.py:
##########
@@ -86,9 +88,32 @@ def execute_async(
             )
         )
 
-    @provide_session
-    def sync(self, session: Session = NEW_SESSION) -> None:
-        """Sync will get called periodically by the heartbeat method."""
+    def _check_alive_worker(self, session: Session) -> bool:

Review Comment:
   Naming suggestion: `worker liveness`?
   ```suggestion
       def _check_worker_liveness(self, session: Session) -> bool:
   ```



##########
providers/src/airflow/providers/edge/CHANGELOG.rst:
##########
@@ -27,6 +27,14 @@
 Changelog
 ---------
 
+0.3.0pre0
+.........
+
+Misc
+~~~~
+
+* ``Edge Worker state is set ot unkown if worker heartbeat timed out.``

Review Comment:
   Typo?



##########
providers/src/airflow/providers/edge/executors/edge_executor.py:
##########
@@ -86,9 +88,32 @@ def execute_async(
             )
         )
 
-    @provide_session
-    def sync(self, session: Session = NEW_SESSION) -> None:
-        """Sync will get called periodically by the heartbeat method."""
+    def _check_alive_worker(self, session: Session) -> bool:
+        """Reset worker state if heartbeat timed out."""
+        changed = False
+        heartbeat_interval: int = conf.getint("edge", "heartbeat_interval")
+        workers: list[EdgeWorkerModel] = session.query(EdgeWorkerModel).all()
+
+        for worker in workers:
+            connected = 1
+            if not worker.last_update or worker.last_update < (
+                timezone.utcnow() - timedelta(seconds=heartbeat_interval * 5)
+            ):

Review Comment:
   Can you please make this selection into the query to push down the filter to 
the DB level, not calling `all()` on the database?



-- 
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]

Reply via email to