-
-
Notifications
You must be signed in to change notification settings - Fork 65
Move worker downtime configuration to workers.py #701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
encukou
wants to merge
4
commits into
python:main
Choose a base branch
from
encukou:config-cleanup-downtime
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+78
−76
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| from datetime import datetime, timedelta | ||
|
|
||
|
|
||
| def no_builds_between(start, end, *, day_of_week=None, tz=None): | ||
| """A function for "builder.canStartBuild" that implements planned downtime | ||
|
|
||
| Avoid a build to be started between start and end time and delay such | ||
| builds until end time. | ||
| """ | ||
|
|
||
| start = datetime.strptime(start, "%H:%M").time() | ||
| end = datetime.strptime(end, "%H:%M").time() | ||
| def canStartBuild(builder, wfb, request): | ||
| now_dt = datetime.now(tz=tz) | ||
| if day_of_week is not None and now_dt.weekday() != day_of_week: | ||
| return True | ||
| now = now_dt.time() | ||
| if is_within_time_range(now, start, end): | ||
| delay = get_delay(now, end) | ||
| # Adapted from: https://docs.buildbot.net/current/manual/customization.html#canstartbuild-functions | ||
| wfb.worker.quarantine_timeout = delay | ||
| wfb.worker.putInQuarantine() | ||
| # This does not take the worker out of quarantine, it only resets | ||
| # the timeout value to default (restarting the default | ||
| # exponential backoff) | ||
| wfb.worker.resetQuarantine() | ||
| return False | ||
| # Schedule the build now | ||
| return True | ||
| return canStartBuild | ||
|
|
||
|
|
||
| def is_within_time_range(now, start, end): | ||
| if start <= end: | ||
| return start <= now <= end | ||
| else: | ||
| return now >= start or now <= end | ||
|
|
||
|
|
||
| def get_delay(now, end): | ||
| today = datetime.today() | ||
| now = datetime.combine(today, now) | ||
| end = datetime.combine(today, end) | ||
|
|
||
| if now > end: | ||
| end += timedelta(days=1) | ||
|
|
||
| difference = end - now | ||
| return difference.total_seconds() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -14,7 +14,7 @@ import os | |||
| import subprocess | ||||
| import sys | ||||
|
|
||||
| from datetime import datetime, timedelta | ||||
| from datetime import timedelta | ||||
| from functools import partial | ||||
| from zoneinfo import ZoneInfo | ||||
|
|
||||
|
|
@@ -52,6 +52,7 @@ from custom.builders import ( # noqa: E402 | |||
| STABLE, | ||||
| ONLY_MAIN_BRANCH, | ||||
| ) | ||||
| from custom.worker_downtime import no_builds_between | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like a phantom import?
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||||
|
|
||||
|
|
||||
| def set_up_sentry(): | ||||
|
|
@@ -194,57 +195,13 @@ def is_important_change(change): | |||
| return any(is_important_file(filename) for filename in change.files) | ||||
|
|
||||
|
|
||||
| def is_within_time_range(now, start, end): | ||||
| if start <= end: | ||||
| return start <= now <= end | ||||
| else: | ||||
| return now >= start or now <= end | ||||
|
|
||||
|
|
||||
| def get_delay(now, end): | ||||
| today = datetime.today() | ||||
| now = datetime.combine(today, now) | ||||
| end = datetime.combine(today, end) | ||||
|
|
||||
| if now > end: | ||||
| end += timedelta(days=1) | ||||
|
|
||||
| difference = end - now | ||||
| return difference.total_seconds() | ||||
|
|
||||
|
|
||||
| # Avoid a build to be started between start and end time and delay such build | ||||
| # at end time | ||||
| def no_builds_between(start, end, *, day_of_week=None, tz=None): | ||||
| start = datetime.strptime(start, "%H:%M").time() | ||||
| end = datetime.strptime(end, "%H:%M").time() | ||||
| def canStartBuild(builder, wfb, request): | ||||
| now_dt = datetime.now(tz=tz) | ||||
| if day_of_week is not None and now_dt.weekday() != day_of_week: | ||||
| return True | ||||
| now = now_dt.time() | ||||
| if is_within_time_range(now, start, end): | ||||
| delay = get_delay(now, end) | ||||
| # Adapted from: https://docs.buildbot.net/current/manual/customization.html#canstartbuild-functions | ||||
| wfb.worker.quarantine_timeout = delay | ||||
| wfb.worker.putInQuarantine() | ||||
| # This does not take the worker out of quarantine, it only resets | ||||
| # the timeout value to default (restarting the default | ||||
| # exponential backoff) | ||||
| wfb.worker.resetQuarantine() | ||||
| return False | ||||
| # Schedule the build now | ||||
| return True | ||||
| return canStartBuild | ||||
|
|
||||
|
|
||||
| github_status_builders = [] | ||||
| release_status_builders = [] | ||||
| mail_status_builders = [] | ||||
|
|
||||
| # Regular builders | ||||
|
|
||||
| for branch_num, (git_url, branchname, git_branch) in enumerate(git_branches): | ||||
| for git_url, branchname, git_branch in git_branches: | ||||
| buildernames = [] | ||||
| refleakbuildernames = [] | ||||
| for name, worker, buildfactory, stability, tier in BUILDERS: | ||||
|
|
@@ -308,24 +265,8 @@ for branch_num, (git_url, branchname, git_branch) in enumerate(git_branches): | |||
| locks=[cpulock.access("counting")], | ||||
| ) | ||||
|
|
||||
| # This worker runs pyperformance at 12am UTC. If a build is scheduled between | ||||
| # 10pm UTC and 2am UTC, it will be delayed to 2am UTC. | ||||
| if worker.name == "diegorusso-aarch64-bigmem": | ||||
| builder.canStartBuild = no_builds_between("22:00", "2:00") | ||||
|
|
||||
| # This worker restarts every day at 9am UTC to work around issues stemming from | ||||
| # failing bigmem tests trashing disk space and fragmenting RAM. Builds scheduled | ||||
| # between 07:20am - 9:20am UTC will be delayed to 9:20am UTC. | ||||
| if worker.name == "ambv-bb-win11": | ||||
| builder.canStartBuild = no_builds_between("7:20", "9:20") | ||||
|
|
||||
| # These workers are reprovisioned every Wednesday at 9am PT. Builds | ||||
| # scheduled between 8am - 10am PT on Wednesdays will be delayed to | ||||
| # 10am PT. | ||||
| if worker.name in ("itamaro-win64-srv-22-aws", "itamaro-centos-aws"): | ||||
| builder.canStartBuild = no_builds_between( | ||||
| "8:00", "10:00", day_of_week=2, tz=ZoneInfo("America/Los_Angeles") | ||||
| ) | ||||
| if worker.downtime: | ||||
| builder.canStartBuild = worker.downtime | ||||
|
|
||||
| c["builders"].append(builder) | ||||
|
|
||||
|
|
@@ -397,18 +338,8 @@ for name, worker, buildfactory, stability, tier in BUILDERS: | |||
| locks=[cpulock.access("counting")], | ||||
| ) | ||||
|
|
||||
| # This worker runs pyperformance at 12am. If a build is scheduled between | ||||
| # 10pm and 2am, it will be delayed at 2am. | ||||
| if worker.name == "diegorusso-aarch64-bigmem": | ||||
| builder.canStartBuild = no_builds_between("22:00", "2:00") | ||||
|
|
||||
| # These workers are reprovisioned every Wednesday at 9am PT. Builds | ||||
| # scheduled between 8am - 10am PT on Wednesdays will be delayed to | ||||
| # 10am PT. | ||||
| if worker.name in ("itamaro-win64-srv-22-aws", "itamaro-centos-aws"): | ||||
| builder.canStartBuild = no_builds_between( | ||||
| "8:00", "10:00", day_of_week=2, tz=ZoneInfo("America/Los_Angeles") | ||||
| ) | ||||
| if worker.downtime: | ||||
| builder.canStartBuild = worker.downtime | ||||
|
|
||||
| c["builders"].append(builder) | ||||
|
|
||||
|
|
||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might add
WEDNESDAY = 2toworker_downtime.pyfor extra clarity.