Blame runworker.py

Neal Gompa 55fa35
#!/usr/bin/env python
Pierre-Yves Chibon 6c9788
Pierre-Yves Chibon 67d1cc
from __future__ import unicode_literals, absolute_import
Aurélien Bompard dcf6f6
Pierre-Yves Chibon 6c9788
import argparse
Pierre-Yves Chibon 6c9788
import sys
Pierre-Yves Chibon 6c9788
import os
Pierre-Yves Chibon 6c9788
import subprocess
Pierre-Yves Chibon 6c9788
Pierre-Yves Chibon 6c9788
Pierre-Yves Chibon 73d120
parser = argparse.ArgumentParser(description="Run the Pagure worker")
Pierre-Yves Chibon 6c9788
parser.add_argument(
Pierre-Yves Chibon 73d120
    "--config",
Pierre-Yves Chibon 73d120
    "-c",
Pierre-Yves Chibon 73d120
    dest="config",
Pierre-Yves Chibon 73d120
    help="Configuration file to use for pagure.",
Pierre-Yves Chibon 73d120
)
Pierre-Yves Chibon 6c9788
parser.add_argument(
Pierre-Yves Chibon 73d120
    "--debug",
Pierre-Yves Chibon 73d120
    dest="debug",
Pierre-Yves Chibon 73d120
    action="store_true",
Pierre-Yves Chibon 6c9788
    default=False,
Pierre-Yves Chibon 73d120
    help="Expand the level of data returned.",
Pierre-Yves Chibon 73d120
)
Pierre-Yves Chibon 6c9788
parser.add_argument(
Pierre-Yves Chibon 73d120
    "--noinfo",
Pierre-Yves Chibon 73d120
    dest="noinfo",
Pierre-Yves Chibon 73d120
    action="store_true",
Pierre-Yves Chibon 6c9788
    default=False,
Pierre-Yves Chibon 73d120
    help="Reduce the log level.",
Pierre-Yves Chibon 73d120
)
Pierre-Yves Chibon 6c9788
Pierre-Yves Chibon 6c9788
args = parser.parse_args()
Pierre-Yves Chibon 6c9788
Pierre-Yves Chibon 6c9788
env = {}
Pierre-Yves Chibon 6c9788
if args.config:
Pierre-Yves Chibon 6c9788
    config = args.config
Pierre-Yves Chibon 73d120
    if not config.startswith("/"):
Pierre-Yves Chibon 6c9788
        here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
Pierre-Yves Chibon 6c9788
        config = os.path.join(here, config)
Pierre-Yves Chibon 73d120
    env["PAGURE_CONFIG"] = config
Pierre-Yves Chibon 6c9788
Pierre-Yves Chibon 73d120
cmd = [sys.executable, "-m", "celery", "worker", "-A", "pagure.lib.tasks"]
Pierre-Yves Chibon 6c9788
Pierre-Yves Chibon 6c9788
if args.debug:
Pierre-Yves Chibon 73d120
    cmd.append("--loglevel=debug")
Pierre-Yves Chibon 6c9788
elif args.noinfo:
Pierre-Yves Chibon 6c9788
    pass
Pierre-Yves Chibon 6c9788
else:
Pierre-Yves Chibon 73d120
    cmd.append("--loglevel=info")
Pierre-Yves Chibon 6c9788
Pierre-Yves Chibon ce9edd
subp = subprocess.Popen(cmd, env=env or None)
Pierre-Yves Chibon ce9edd
subp.wait()