Skip to content

Commit 38fd7ec

Browse files
committed
Start with queued runs first when canceling runs in an asset backfill
> Insert changelog entry or delete this section.
1 parent 16f499c commit 38fd7ec

File tree

1 file changed

+17
-2
lines changed
  • python_modules/dagster/dagster/_core/execution

1 file changed

+17
-2
lines changed

python_modules/dagster/dagster/_core/execution/backfill.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from dagster._core.storage.dagster_run import (
2727
CANCELABLE_RUN_STATUSES,
2828
NOT_FINISHED_STATUSES,
29+
DagsterRunStatus,
2930
RunsFilter,
3031
)
3132
from dagster._core.storage.tags import BACKFILL_ID_TAG, USER_TAG
@@ -557,18 +558,32 @@ def cancel_backfill_runs_and_cancellation_complete(
557558

558559
while True:
559560
# Cancel all cancelable runs for the backfill in batches
561+
562+
# start with the queued runs since those will be faster to cancel
560563
runs_to_cancel_in_iteration = instance.run_storage.get_runs(
561564
filters=RunsFilter(
562-
statuses=CANCELABLE_RUN_STATUSES,
565+
statuses=[DagsterRunStatus.QUEUED],
563566
tags={
564567
BACKFILL_ID_TAG: backfill_id,
565568
},
566569
),
567570
limit=CANCELABLE_RUNS_BATCH_SIZE,
568571
ascending=True,
569572
)
573+
570574
if not runs_to_cancel_in_iteration:
571-
break
575+
runs_to_cancel_in_iteration = instance.run_storage.get_runs(
576+
filters=RunsFilter(
577+
statuses=CANCELABLE_RUN_STATUSES,
578+
tags={
579+
BACKFILL_ID_TAG: backfill_id,
580+
},
581+
),
582+
limit=CANCELABLE_RUNS_BATCH_SIZE,
583+
ascending=True,
584+
)
585+
if not runs_to_cancel_in_iteration:
586+
break
572587

573588
canceled_any_runs = True
574589
for run in runs_to_cancel_in_iteration:

0 commit comments

Comments
 (0)