From d4d5d82258b1fa825f02ed4076d79ee6772223c7 Mon Sep 17 00:00:00 2001 From: prha <1040172+prha@users.noreply.github.com> Date: Tue, 29 Oct 2024 13:15:08 -0700 Subject: [PATCH] fix race condition for deleting state (#25618) ## Summary & Motivation In case the scheduler daemon has a stale version of the workspace when the schedule is turned on, we do not want to delete. ## How I Tested These Changes BK (internal) --- python_modules/dagster/dagster/_scheduler/scheduler.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python_modules/dagster/dagster/_scheduler/scheduler.py b/python_modules/dagster/dagster/_scheduler/scheduler.py index 1ca80a66322f6..4c83de5acc5e0 100644 --- a/python_modules/dagster/dagster/_scheduler/scheduler.py +++ b/python_modules/dagster/dagster/_scheduler/scheduler.py @@ -343,9 +343,9 @@ def launch_scheduled_runs( # Remove all-stopped states declared in code immediately. # Also remove all other states that are not present in the workspace after a 12-hour grace period. - if ( - state.status == InstigatorStatus.DECLARED_IN_CODE - or _last_iteration_time + RETAIN_ORPHANED_STATE_INTERVAL_SECONDS + if state.status == InstigatorStatus.DECLARED_IN_CODE or ( + _last_iteration_time + and _last_iteration_time + RETAIN_ORPHANED_STATE_INTERVAL_SECONDS < end_datetime_utc.timestamp() ): logger.info(