Skip to content

task instance listener: call on_task_instance_running after rendering templates#32716

Merged
mobuchowski merged 1 commit into
mainfrom
listener-move-onrunning-callback
Jul 25, 2023
Merged

task instance listener: call on_task_instance_running after rendering templates#32716
mobuchowski merged 1 commit into
mainfrom
listener-move-onrunning-callback

Conversation

@mobuchowski

Copy link
Copy Markdown
Contributor

Previously, on_task_instance_running was being called in _run_raw_task. After this, it will be running close to where pre_execute callback is called.

This had disadvantage of being run before operator templates are rendered.
In some usages, this required users of this interface (like OpenLineage) to resolve templates themselves, which comes with obvious performance drawback. Now, the state of actual executed task is the same as on execute.

Another reason of moving call site is that idea of task instance listener API is to provide notification as close to when actual execution happens. This is as close as we can get AFAIK.

@mobuchowski
mobuchowski requested review from eladkal and potiuk July 20, 2023 12:26
@mobuchowski
mobuchowski force-pushed the listener-move-onrunning-callback branch from 983dcc9 to 3c7ba73 Compare July 20, 2023 12:26
@mobuchowski mobuchowski reopened this Jul 20, 2023
Comment thread airflow/models/taskinstance.py Outdated
Comment thread airflow/models/taskinstance.py Outdated
@mobuchowski
mobuchowski force-pushed the listener-move-onrunning-callback branch from 3c7ba73 to 53d31fd Compare July 21, 2023 10:46
@mobuchowski
mobuchowski requested a review from uranusjr July 21, 2023 15:35
Comment on lines +1649 to +1650
# Is never MappedOperator at this point
self.task.pre_execute(context=context) # type: ignore[union-attr]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the task unmapped before this line is reached? How can we be sure this is the case?

@mobuchowski mobuchowski Jul 24, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@uranusjr I'm actually going by your code 😉 - render templates is just before that.

5560a46

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact I wrote the code is not a particularly promising guarantee though 😛

But code here is pretty awful. I’ll add a commit to better fix this up later…

@mobuchowski
mobuchowski merged commit ca20251 into main Jul 25, 2023
@ephraimbuddy ephraimbuddy added the type:improvement Changelog: Improvements label Aug 2, 2023
@ephraimbuddy ephraimbuddy added this to the Airflow 2.7.0 milestone Aug 2, 2023
@Taragolis
Taragolis deleted the listener-move-onrunning-callback branch September 26, 2023 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:improvement Changelog: Improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants