@@ -14,7 +14,7 @@ import os
1414import subprocess
1515import sys
1616
17- from datetime import datetime , timedelta
17+ from datetime import timedelta
1818from functools import partial
1919from zoneinfo import ZoneInfo
2020
@@ -52,6 +52,7 @@ from custom.builders import ( # noqa: E402
5252 STABLE ,
5353 ONLY_MAIN_BRANCH ,
5454)
55+ from custom .worker_downtime import no_builds_between
5556
5657
5758def set_up_sentry ():
@@ -194,50 +195,6 @@ def is_important_change(change):
194195 return any (is_important_file (filename ) for filename in change .files )
195196
196197
197- def is_within_time_range (now , start , end ):
198- if start <= end :
199- return start <= now <= end
200- else :
201- return now >= start or now <= end
202-
203-
204- def get_delay (now , end ):
205- today = datetime .today ()
206- now = datetime .combine (today , now )
207- end = datetime .combine (today , end )
208-
209- if now > end :
210- end += timedelta (days = 1 )
211-
212- difference = end - now
213- return difference .total_seconds ()
214-
215-
216- # Avoid a build to be started between start and end time and delay such build
217- # at end time
218- def no_builds_between (start , end , * , day_of_week = None , tz = None ):
219- start = datetime .strptime (start , "%H:%M" ).time ()
220- end = datetime .strptime (end , "%H:%M" ).time ()
221- def canStartBuild (builder , wfb , request ):
222- now_dt = datetime .now (tz = tz )
223- if day_of_week is not None and now_dt .weekday () != day_of_week :
224- return True
225- now = now_dt .time ()
226- if is_within_time_range (now , start , end ):
227- delay = get_delay (now , end )
228- # Adapted from: https://docs.buildbot.net/current/manual/customization.html#canstartbuild-functions
229- wfb .worker .quarantine_timeout = delay
230- wfb .worker .putInQuarantine ()
231- # This does not take the worker out of quarantine, it only resets
232- # the timeout value to default (restarting the default
233- # exponential backoff)
234- wfb .worker .resetQuarantine ()
235- return False
236- # Schedule the build now
237- return True
238- return canStartBuild
239-
240-
241198github_status_builders = []
242199release_status_builders = []
243200mail_status_builders = []
0 commit comments