-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathlocks.py
41 lines (33 loc) · 1.16 KB
/
locks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import yaml
from buildbot.plugins import util
# Local
from constants import BUILDERS_INSTALL, BUILDERS_UPGRADE, GITHUB_STATUS_BUILDERS
LOCKS: dict[str, util.MasterLock] = {}
# worker_locks.yaml currently is in the same folder as locks.py.
# TODO: re-evaluate if this is the right place after multi-master
# is refactored to use a single base master.cfg.
with open(
os.path.join(os.path.dirname(os.path.realpath(__file__)), "worker_locks.yaml"),
encoding="utf-8",
) as file:
locks = yaml.safe_load(file)
for worker_name in locks:
LOCKS[worker_name] = util.MasterLock(
f"{worker_name}_lock", maxCount=locks[worker_name]
)
@util.renderer
def getLocks(props):
worker_name = props.getProperty("workername", default=None)
builder_name = props.getProperty("buildername", default=None)
assert worker_name is not None
assert builder_name is not None
if (
builder_name in GITHUB_STATUS_BUILDERS
or builder_name in BUILDERS_INSTALL
or builder_name in BUILDERS_UPGRADE
):
return []
if worker_name not in LOCKS:
return []
return [LOCKS[worker_name].access("counting")]