Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logic to cancel the external job if the TaskInstance is not in a running or deferred state for BigQueryInsertJobOperator #39442

Merged
merged 7 commits into from
May 8, 2024

Conversation

sunank200
Copy link
Collaborator

@sunank200 sunank200 commented May 6, 2024

PR #38912 introduces a method for handling asyncio.CancelledError in a try/except block. However, this method is deemed unsafe, and it affects BigQueryInsertJobOperator operators, which enables external job cancellation if the triggerer restarts or crashes. This can cause weird behaviour like rescheduling deferred operators, as Airflow remains unaware of job cancellations.

As a workaround, capturing asyncio.CancelledError cancels the job only if the TaskInstance is not in a running or deferred state. This prevents premature external job termination.

More details at: #36090 (comment)


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

@sunank200
Copy link
Collaborator Author

@thesuperzapper please take a look

@sunank200 sunank200 force-pushed the BigQueryInsertJobOperatorfix branch from 2e9a14d to b265f02 Compare May 6, 2024 19:40
@Lee-W
Copy link
Member

Lee-W commented May 7, 2024

Just have a quick discussion with @sunank200. We'll yield the event if CancelError was raised , and handle the TaskInstance state check and cancelation in execute_complete

@sunank200
Copy link
Collaborator Author

sunank200 commented May 7, 2024

Just have a quick discussion with @sunank200. We'll yield the event if CancelError was raised , and handle the TaskInstance state check and cancelation in execute_complete

This approach would not work as execute on complete is not called when the task is manually cancelled when inside triggerer

@sunank200 sunank200 force-pushed the BigQueryInsertJobOperatorfix branch 2 times, most recently from 04e55ee to b71e41c Compare May 7, 2024 13:03
Copy link
Member

@pankajkoti pankajkoti left a comment

Choose a reason for hiding this comment

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

LGTM. Some minor suggestions inline

airflow/providers/google/cloud/triggers/bigquery.py Outdated Show resolved Hide resolved
@sunank200 sunank200 force-pushed the BigQueryInsertJobOperatorfix branch from b71e41c to 8a24aa7 Compare May 7, 2024 13:58
@sunank200 sunank200 force-pushed the BigQueryInsertJobOperatorfix branch from 9335924 to 7b2af60 Compare May 7, 2024 15:04
@sunank200
Copy link
Collaborator Author

@thesuperzapper Please take a look I have tested this and it works fine.

@sunank200 sunank200 requested review from Taragolis, thesuperzapper and tirkarthi and removed request for tirkarthi and thesuperzapper May 7, 2024 15:05
@sunank200 sunank200 force-pushed the BigQueryInsertJobOperatorfix branch from 7b2af60 to 35d61c2 Compare May 8, 2024 06:47
@sunank200 sunank200 force-pushed the BigQueryInsertJobOperatorfix branch from 35d61c2 to 770010a Compare May 8, 2024 07:58
@Lee-W Lee-W merged commit e7aa4d2 into apache:main May 8, 2024
39 checks passed
@Lee-W Lee-W deleted the BigQueryInsertJobOperatorfix branch May 8, 2024 08:55
RodrigoGanancia pushed a commit to RodrigoGanancia/airflow that referenced this pull request May 10, 2024
…running or deferred state for BigQueryInsertJobOperator (apache#39442)
pateash pushed a commit to pateash/airflow that referenced this pull request May 13, 2024
…running or deferred state for BigQueryInsertJobOperator (apache#39442)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:providers provider:google Google (including GCP) related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants