forked from mozilla/stoneridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
srdeferrer.py
71 lines (56 loc) · 2.42 KB
/
srdeferrer.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at http://mozilla.org/MPL/2.0/.
import os
import sys
import time
import stoneridge
class StoneRidgeDeferrer(object):
def __init__(self, srid, nightly, ldap, sha, netconfigs, operating_systems,
attempt):
self.srid = srid
self.nightly = nightly
self.ldap = ldap
self.sha = sha
self.netconfigs = netconfigs
self.operating_systems = operating_systems
self.attempt = attempt
self.interval = stoneridge.get_config_int('cloner', 'interval')
def run(self):
start = int(time.time())
end = start + self.interval
now = start
while now < end:
# Sleep for short periods in an attempt to not get too skewed
time.sleep(30)
now = int(time.time())
stoneridge.enqueue(srid=self.srid, nightly=self.nightly,
ldap=self.ldap, sha=self.sha,
netconfigs=self.netconfigs,
operating_systems=self.operating_systems,
attempt=self.attempt)
def daemon(deferrer, args):
deferrer.run()
os.unlink(args.pidfile)
sys.exit(0)
@stoneridge.main
def main():
parser = stoneridge.DaemonArgumentParser()
parser.add_argument('--srid', dest='srid', required=True)
parser.add_argument('--attempt', dest='attempt', type=int, required=True)
parser.add_argument('--nightly', dest='nightly', action='store_true',
default=False)
parser.add_argument('--ldap', dest='ldap', default='')
parser.add_argument('--sha', dest='sha', default='')
for nc in stoneridge.NETCONFIGS:
parser.add_argument('--%s' % (nc,), dest='netconfigs',
action='append_const', const=nc, default=[])
for ops in stoneridge.OPERATING_SYSTEMS:
parser.add_argument('--%s' % (ops,), dest='operating_systems',
action='append_const', const=ops, default=[])
args = parser.parse_args()
deferrer = StoneRidgeDeferrer(args.srid, args.nightly, args.ldap, args.sha,
args.netconfigs, args.operating_systems,
args.attempt)
parser.start_daemon(daemon, deferrer=deferrer, args=args)