Cancel Snowflake queries when a user kills the deferred task#69635
Open
steveahnahn wants to merge 1 commit into
Open
Cancel Snowflake queries when a user kills the deferred task#69635steveahnahn wants to merge 1 commit into
steveahnahn wants to merge 1 commit into
Conversation
a7c612b to
a878441
Compare
A deferred SnowflakeSqlApiOperator parks its running query ids in the triggerer, so the operator's own on_kill no longer runs once the task is deferred. When a user marks that task failed, clears it, or marks it success, SnowflakeSqlApiTrigger had no on_kill hook, so the Snowflake statements kept executing on the warehouse, burning compute credits, even though the operator already cancels the queries on kill in the non-deferred path. This adds on_kill to SnowflakeSqlApiTrigger to cancel the running query ids when the user acts on the deferred task, matching the behaviour already shipped for the EMR, Dataproc, BigQuery, and Dataflow triggers. The Snowflake SQL API cancel is a blocking POST with no async variant, so it runs through sync_to_async off the triggerer event loop, and the hook is built inside that worker so no connection work touches the loop. A cancel_on_kill flag on both the operator and the trigger lets users opt out.
a878441 to
0bad94d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
SnowflakeSqlApiOperator.on_killcancels the running queries, but afterdefer()the worker is gone and it can never run.SnowflakeSqlApiTriggerhad noon_kill(base default is a no op), so killing a deferred task leaves the statements executing on the warehouse, burning credits.Change
on_killtoSnowflakeSqlApiTrigger: cancels the running query ids.POSTwith no async variant, soon_killrunscancel_queriesthroughsync_to_async, building the hook inside that worker so no connection work touches the event loop.cancel_on_killflag (defaultTrue) on operator and trigger; operator threads it into the trigger at the defer site.Live verification
deferred, trigger polling (GET /api/v2/statements/{id}returning 202).POST /api/v2/statements/{id}/canceland the statement transitioned toABORTED. Without the change it stays running.Tests
cancel_on_kill=Falseguard, flag threaded into the trigger on defer.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Fable 5) following the guidelines