xBis7 commented on code in PR #49180:
URL: https://github.com/apache/airflow/pull/49180#discussion_r2064322763
##########
airflow-core/src/airflow/jobs/scheduler_job_runner.py:
##########
@@ -1058,27 +1060,25 @@ def _update_dag_run_state_for_paused_dags(self,
session: Session = NEW_SESSION)
@provide_session
def _end_active_spans(self, session: Session = NEW_SESSION):
# No need to do a commit for every update. The annotation will commit
all of them once at the end.
- for key, span in self.active_spans.get_all().items():
- from airflow.models.taskinstance import TaskInstanceKey
-
- if isinstance(key, TaskInstanceKey): # ti span.
- # Can't compare the key directly because the try_number or the
map_index might not be the same.
- ti: TaskInstance = session.scalars(
- select(TaskInstance).where(
- TaskInstance.dag_id == key.dag_id,
- TaskInstance.task_id == key.task_id,
- TaskInstance.run_id == key.run_id,
- )
- ).one()
- if ti.state in State.finished:
- self.set_ti_span_attrs(span=span, state=ti.state, ti=ti)
- span.end(end_time=datetime_to_nano(ti.end_date))
- ti.span_status = SpanStatus.ENDED
- else:
- span.end()
- ti.span_status = SpanStatus.NEEDS_CONTINUANCE
- else:
- dag_run: DagRun =
session.scalars(select(DagRun).where(DagRun.run_id == key)).one()
+ for prefixed_key, span in self.active_spans.get_all().items():
+ # Use partition to split on the first occurrence of ':'.
+ prefix, sep, key = prefixed_key.partition(":")
+
+ if prefix == "ti":
+ ti: TaskInstance | None = session.scalars(
+ select(TaskInstance).where(TaskInstance.id == key)
+ ).one_or_none()
+
+ if ti is not None:
+ if ti.state in State.finished:
+ self.set_ti_span_attrs(span=span, state=ti.state,
ti=ti)
+ span.end(end_time=datetime_to_nano(ti.end_date))
+ ti.span_status = SpanStatus.ENDED
+ else:
+ span.end()
+ ti.span_status = SpanStatus.NEEDS_CONTINUANCE
+ elif prefix == "dr":
+ dag_run: DagRun =
session.scalars(select(DagRun).where(DagRun.run_id == str(key))).one()
Review Comment:
I changed it to use `id`.
--
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]