4747)
4848from ...core .settings import ComputationalBackendSettings
4949from ...models .comp_pipelines import CompPipelineAtDB
50- from ...models .comp_runs import CompRunsAtDB , RunMetadataDict
50+ from ...models .comp_runs import RunMetadataDict
5151from ...models .comp_tasks import CompTaskAtDB
5252from ...utils .comp_scheduler import (
5353 COMPLETED_STATES ,
@@ -131,7 +131,7 @@ async def _triage_changed_tasks(
131131class ScheduledPipelineParams :
132132 cluster_id : ClusterID
133133 run_metadata : RunMetadataDict
134- mark_for_cancellation : bool = False
134+ mark_for_cancellation : datetime . datetime | None
135135 use_on_demand_clusters : bool
136136
137137
@@ -169,7 +169,7 @@ async def run_new_pipeline(
169169 return
170170
171171 runs_repo = CompRunsRepository .instance (self .db_engine )
172- new_run : CompRunsAtDB = await runs_repo .create (
172+ new_run = await runs_repo .create (
173173 user_id = user_id ,
174174 project_id = project_id ,
175175 cluster_id = cluster_id ,
@@ -182,6 +182,7 @@ async def run_new_pipeline(
182182 cluster_id = cluster_id ,
183183 run_metadata = new_run .metadata ,
184184 use_on_demand_clusters = use_on_demand_clusters ,
185+ mark_for_cancellation = None ,
185186 )
186187 await publish_project_log (
187188 self .rabbitmq_client ,
@@ -212,11 +213,18 @@ async def stop_pipeline(
212213 selected_iteration = iteration
213214
214215 # mark the scheduled pipeline for stopping
215- self .scheduled_pipelines [
216- (user_id , project_id , selected_iteration )
217- ].mark_for_cancellation = True
218- # ensure the scheduler starts right away
219- self ._wake_up_scheduler_now ()
216+ updated_comp_run = await CompRunsRepository .instance (
217+ self .db_engine
218+ ).mark_for_cancellation (
219+ user_id = user_id , project_id = project_id , iteration = selected_iteration
220+ )
221+ if updated_comp_run :
222+ assert updated_comp_run .cancelled is not None # nosec
223+ self .scheduled_pipelines [
224+ (user_id , project_id , selected_iteration )
225+ ].mark_for_cancellation = updated_comp_run .cancelled
226+ # ensure the scheduler starts right away
227+ self ._wake_up_scheduler_now ()
220228
221229 async def schedule_all_pipelines (self ) -> None :
222230 self .wake_up_event .clear ()
@@ -343,7 +351,7 @@ def _need_heartbeat(task: CompTaskAtDB) -> bool:
343351 if task .last_heartbeat is None :
344352 assert task .start # nosec
345353 return bool (
346- (utc_now - task .start .replace (tzinfo = datetime .timezone . utc ))
354+ (utc_now - task .start .replace (tzinfo = datetime .UTC ))
347355 > self .service_runtime_heartbeat_interval
348356 )
349357 return bool (
0 commit comments