This repository has been archived by the owner on Apr 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
start.py
49 lines (37 loc) · 1.61 KB
/
start.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
import argparse
import config
from celery.bin import worker as Worker
from scoring import celery_app, engine
def main(args):
if args.reset:
engine.execute("TRUNCATE checks; TRUNCATE rounds; TRUNCATE celery_taskmeta;")
round = args.round
if args.resume:
lastRound = engine.execute("SELECT MAX(number) FROM rounds").first()
round = lastRound[0] + 1
# ScoreEngine will automatically start at
# round+1, so subtract 1 if we're given a round
if round > 0:
round -= 1
if args.worker:
celery_app.autodiscover_tasks(['scoring.worker'])
worker = Worker.worker(app=celery_app)
worker.run(**config.CELERY["WORKER"])
else:
if args.queue:
from scoring.master2 import Master
else:
from scoring.master import Master
master = Master(round=round)
master.run()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='ScoreEngine control center')
group_round = parser.add_mutually_exclusive_group()
group_round.add_argument('--round', help='round to start at', type=int, default=0)
group_round.add_argument('--resume', help='start with the highest finished round', action='store_true', default=False)
group_round.add_argument('--reset', help='reset all existing checks', action='store_true', default=False)
group_type = parser.add_mutually_exclusive_group(required=True)
group_type.add_argument('--master', help='do not use the task queue', action='store_true')
group_type.add_argument('--queue', help='become the master of the task queue', action='store_true')
group_type.add_argument('--worker', help='only handle checks from the task queue', action='store_true')
main(parser.parse_args())