@@ -81,14 +81,11 @@ async def worker_synchronize_dataadmins(skip_beamlines=False) -> None:
8181 f"Beamline Data Admin permissions synchronized in { time_taken .total_seconds ():,.2f} seconds"
8282 )
8383
84-
8584async def worker_synchronize_cycles_from_pass (
8685 facility_name : FacilityName = FacilityName .nsls2 ,
8786) -> None :
8887 """
89- This method synchronizes the cycles for a facility from PASS.
90-
91- :param facility_name: The facility name (FacilityName).
88+ Synchronize cycles for a facility from PASS and set the current cycle.
9289 """
9390 start_time = datetime .datetime .now ()
9491
@@ -136,7 +133,7 @@ async def worker_synchronize_cycles_from_pass(
136133 response_type = UpdateResponse .NEW_DOCUMENT ,
137134 )
138135
139- # Now let's update the list of proposals for this cycle
136+ # Update proposals for this cycle
140137 proposals_list = await pass_service .get_proposals_allocated_by_cycle (
141138 cycle .name , facility = facility_name
142139 )
@@ -147,6 +144,23 @@ async def worker_synchronize_cycles_from_pass(
147144 updated_cycle .last_updated = datetime .datetime .now ()
148145 await updated_cycle .save ()
149146
147+ # --- Set current operating cycle from today's date ---
148+ today = datetime .datetime .now ()
149+ found_cycle = await facility_service .facility_cycle_by_date (facility_name , today )
150+ if not found_cycle :
151+ logger .warning (
152+ f"No cycle found for today's date in facility { facility_name } "
153+ )
154+ else :
155+ logger .info (
156+ f"Found cycle { found_cycle .name } for today's date in facility { facility_name } "
157+ )
158+ # Set the current operating cycle for the facility
159+ await facility_service .set_current_operating_cycle (facility_name , found_cycle .name )
160+ logger .info (
161+ f"Set current operating cycle for { facility_name } to { found_cycle .name } "
162+ )
163+
150164 time_taken = datetime .datetime .now () - start_time
151165 logger .info (
152166 f"Cycle information (for { facility_name } ) synchronized in { time_taken .total_seconds ():,.2f} seconds"
0 commit comments