Skip to content

Commit ccd4457

Browse files
authored
Allow specific pipelines to run at higher priority (#2106)
Also formatted bazelci.py
1 parent b05134e commit ccd4457

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

buildkite/bazelci.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,10 @@
484484
_SHARD_RE = re.compile(r"(.+) \(shard (\d+)\)")
485485
_SLOWEST_N_TARGETS = 20
486486

487+
# Pipelines with elevated priority. Values are project slugs,
488+
# i.e. "org_slug/pipeline_slug".
489+
_PRIORITY_PIPELINES = frozenset(["bazel/google-bazel-presubmit"])
490+
487491

488492
class BuildkiteException(Exception):
489493
"""
@@ -580,11 +584,13 @@ def _open_url(self, url, params=[], retries=5):
580584
if retry_after:
581585
wait_time = int(retry_after)
582586
else:
583-
wait_time = (2 ** attempt) # Exponential backoff if no RateLimit-Reset header
587+
wait_time = 2**attempt # Exponential backoff if no RateLimit-Reset header
584588

585589
time.sleep(wait_time)
586590
else:
587-
raise BuildkiteException("Failed to open {}: {} - {}".format(url, ex.code, ex.reason))
591+
raise BuildkiteException(
592+
"Failed to open {}: {} - {}".format(url, ex.code, ex.reason)
593+
)
588594

589595
raise BuildkiteException(f"Failed to open {url} after {retries} retries.")
590596

@@ -968,7 +974,9 @@ def load_imported_tasks(import_name, http_url, file_config, bazel_version):
968974
else:
969975
file_config = new_path
970976

971-
imported_config = load_config(http_url=http_url, file_config=file_config, allow_imports=False, bazel_version=bazel_version)
977+
imported_config = load_config(
978+
http_url=http_url, file_config=file_config, allow_imports=False, bazel_version=bazel_version
979+
)
972980

973981
namespace = import_name.partition(".")[0]
974982
tasks = {}
@@ -2669,7 +2677,9 @@ def terminate_background_process(process):
26692677
process.kill()
26702678

26712679

2672-
def create_step(label, commands, platform, shards=1, soft_fail=None, concurrency=None, concurrency_group=None):
2680+
def create_step(
2681+
label, commands, platform, shards=1, soft_fail=None, concurrency=None, concurrency_group=None
2682+
):
26732683
if "docker-image" in PLATFORMS[platform]:
26742684
step = create_docker_step(
26752685
label,
@@ -2685,6 +2695,12 @@ def create_step(label, commands, platform, shards=1, soft_fail=None, concurrency
26852695
"agents": {"queue": PLATFORMS[platform]["queue"]},
26862696
}
26872697

2698+
project_slug = "{}/{}".format(
2699+
os.getenv("BUILDKITE_ORGANIZATION_SLUG"), os.getenv("BUILDKITE_PIPELINE_SLUG")
2700+
)
2701+
if project_slug in _PRIORITY_PIPELINES:
2702+
step["priority"] = 1
2703+
26882704
if shards > 1:
26892705
# %N means shard counting starts at 1, not 0
26902706
step["label"] += " (shard %N)"
@@ -4351,7 +4367,11 @@ def main(argv=None):
43514367
runner.add_argument("--task", action="store", type=str, default="")
43524368
runner.add_argument("--file_config", type=str)
43534369
runner.add_argument("--http_config", type=str)
4354-
runner.add_argument("--overwrite_bazel_version", type=str, help="Overwrite the bazel version in the config file.")
4370+
runner.add_argument(
4371+
"--overwrite_bazel_version",
4372+
type=str,
4373+
help="Overwrite the bazel version in the config file.",
4374+
)
43554375
runner.add_argument("--git_repository", type=str)
43564376
runner.add_argument(
43574377
"--git_commit", type=str, help="Reset the git repository to this commit after cloning it"
@@ -4456,7 +4476,9 @@ def main(argv=None):
44564476
old_bazel = task_config.get("old_bazel")
44574477
if old_bazel:
44584478
new_bazel = task_config.get("bazel")
4459-
print_collapsed_group(f":bazel: Bazel version overridden from {old_bazel} to {new_bazel}")
4479+
print_collapsed_group(
4480+
f":bazel: Bazel version overridden from {old_bazel} to {new_bazel}"
4481+
)
44604482

44614483
execute_commands(
44624484
task_config=task_config,

0 commit comments

Comments
 (0)