-
Notifications
You must be signed in to change notification settings - Fork 45
/
runworker.py
executable file
·74 lines (64 loc) · 1.55 KB
/
runworker.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
72
73
74
#!/usr/bin/env python
from __future__ import unicode_literals, absolute_import
import argparse
import sys
import os
import subprocess
parser = argparse.ArgumentParser(description="Run the Pagure worker")
parser.add_argument(
"--config",
"-c",
dest="config",
help="Configuration file to use for pagure.",
)
parser.add_argument(
"--debug",
dest="debug",
action="store_true",
default=False,
help="Expand the level of data returned.",
)
parser.add_argument(
"--queue",
dest="queue",
default=None,
help="Name of the queue to run the worker against.",
)
parser.add_argument(
"--tasks",
dest="tasks",
default="pagure.lib.tasks",
help="Class used by the workers.",
)
parser.add_argument(
"--noinfo",
dest="noinfo",
action="store_true",
default=False,
help="Reduce the log level.",
)
parser.add_argument(
"--name",
dest="name",
default="worker",
help="Name of the celery worker, has to be unique.",
)
args = parser.parse_args()
env = os.environ
if args.config:
config = args.config
if not config.startswith("/"):
here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
config = os.path.join(here, config)
env["PAGURE_CONFIG"] = config
cmd = [sys.executable, "-m", "celery", "-A", args.tasks, "worker", "-n", args.name]
if args.queue:
cmd.extend(["-Q", args.queue])
if args.debug:
cmd.append("--loglevel=debug")
elif args.noinfo:
pass
else:
cmd.append("--loglevel=info")
subp = subprocess.Popen(cmd, env=env or None)
subp.wait()