stoneridge/srdeferrer.py

72 строки
2.4 KiB
Python
Исходник Постоянная ссылка Обычный вид История

#!/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/.
2013-02-01 01:32:00 +04:00
import os
2013-01-16 00:33:02 +04:00
import sys
import time
import stoneridge
class StoneRidgeDeferrer(object):
def __init__(self, srid, nightly, ldap, sha, netconfigs, operating_systems,
2013-02-20 04:22:00 +04:00
attempt):
self.srid = srid
self.nightly = nightly
self.ldap = ldap
self.sha = sha
self.netconfigs = netconfigs
self.operating_systems = operating_systems
self.attempt = attempt
2013-01-16 00:33:02 +04:00
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())
2013-02-21 08:20:22 +04:00
stoneridge.enqueue(srid=self.srid, nightly=self.nightly,
ldap=self.ldap, sha=self.sha,
netconfigs=self.netconfigs,
2013-02-20 04:22:00 +04:00
operating_systems=self.operating_systems,
attempt=self.attempt)
2013-01-16 00:33:02 +04:00
def daemon(deferrer, args):
deferrer.run()
os.unlink(args.pidfile)
sys.exit(0)
@stoneridge.main
def main():
2013-01-16 00:33:02 +04:00
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',
2013-02-20 04:22:00 +04:00
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',
2013-02-20 04:22:00 +04:00
action='append_const', const=nc, default=[])
for ops in stoneridge.OPERATING_SYSTEMS:
parser.add_argument('--%s' % (ops,), dest='operating_systems',
2013-02-20 04:22:00 +04:00
action='append_const', const=ops, default=[])
args = parser.parse_args()
deferrer = StoneRidgeDeferrer(args.srid, args.nightly, args.ldap, args.sha,
2013-02-20 04:22:00 +04:00
args.netconfigs, args.operating_systems,
args.attempt)
2013-01-16 00:33:02 +04:00
parser.start_daemon(daemon, deferrer=deferrer, args=args)