ashb commented on code in PR #60855:
URL: https://github.com/apache/airflow/pull/60855#discussion_r2732024592
##########
task-sdk/src/airflow/sdk/execution_time/supervisor.py:
##########
@@ -2088,6 +2102,10 @@ def supervise(
final_state=process.final_state,
)
return exit_code
+ except TaskAlreadyRunningError:
+ # Let the executor handle this (e.g., Celery will ignore it)
+ log.info("Exiting due to broker redelivery",
task_instance_id=str(ti.id))
Review Comment:
"broker" as a concept only exist for Celery, so this log message doesn't
make sense for other executors.
##########
task-sdk/src/airflow/sdk/execution_time/supervisor.py:
##########
@@ -1007,9 +1007,23 @@ def _on_child_started(
ti_context = self.client.task_instances.start(ti.id, self.pid,
start_date)
self._should_retry = ti_context.should_retry
self._last_successful_heartbeat = time.monotonic()
- except Exception:
+ except Exception as e:
# On any error kill that subprocess!
self.kill(signal.SIGKILL)
+
+ # Handle broker redelivery: task already running on another worker
+ if isinstance(e, ServerResponseError) and e.response.status_code
== 409:
+ # FastAPI wraps HTTPException detail in {"detail": {...}}
+ detail = e.detail
+ if isinstance(detail, dict) and "detail" in detail:
+ detail = detail["detail"]
+ if (
+ isinstance(detail, dict)
+ and detail.get("reason") == "invalid_state"
+ and detail.get("previous_state") == "running"
+ ):
Review Comment:
This is rather fragile and not a good idea to write things this way.
--
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]