1212 ScheduleOverlapPolicy ,
1313 SchedulePolicy ,
1414 ScheduleSpec ,
15+ ScheduleState ,
1516 ScheduleUpdate ,
1617 ScheduleUpdateInput ,
1718)
4344 # Will be updated at startup with the value from the db
4445 intervals = [ScheduleIntervalSpec (every = timedelta (minutes = 60 ))]
4546 ),
47+ # Will be updated at startup with the value from the db
48+ state = ScheduleState (paused = True ),
4649 policy = SchedulePolicy (overlap = ScheduleOverlapPolicy .CANCEL_OTHER ),
4750 ),
4851}
4952
5053
51- def _master_image_sync_updater (sync_interval_minutes : int ):
54+ def _master_image_sync_updater (
55+ sync_interval_minutes : int , auto_import_enabled_config : bool | None = None
56+ ):
5257 async def do_update (input : ScheduleUpdateInput ) -> ScheduleUpdate :
5358 master_image_sync_schedule = SCHEDULES [MASTER_IMAGE_SYNC_WORKFLOW_NAME ]
5459 master_image_sync_schedule .spec = ScheduleSpec (
@@ -63,6 +68,9 @@ async def do_update(input: ScheduleUpdateInput) -> ScheduleUpdate:
6368 # Here we save the current state in order to avoid un-pausing the schedule
6469 # when only changing the sync interval
6570 current_state = schedule_description .schedule .state
71+ if auto_import_enabled_config is not None :
72+ # On startup, set the state based on the config
73+ current_state .paused = not auto_import_enabled_config
6674 schedule_description .schedule = master_image_sync_schedule
6775 schedule_description .schedule .state = current_state
6876 return ScheduleUpdate (schedule = schedule_description .schedule )
@@ -71,11 +79,15 @@ async def do_update(input: ScheduleUpdateInput) -> ScheduleUpdate:
7179
7280
7381async def update_master_image_sync_schedule_interval (
74- client : Client , sync_interval_minutes_config : int
82+ client : Client ,
83+ sync_interval_minutes_config : int ,
84+ auto_import_enabled_config : bool | None = None ,
7585):
7686 handle = client .get_schedule_handle (MASTER_IMAGE_SYNC_WORKFLOW_NAME )
7787 await handle .update (
78- _master_image_sync_updater (sync_interval_minutes_config )
88+ _master_image_sync_updater (
89+ sync_interval_minutes_config , auto_import_enabled_config
90+ )
7991 )
8092
8193
0 commit comments