runworker.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/env python
  2. from __future__ import unicode_literals, absolute_import
  3. import argparse
  4. import sys
  5. import os
  6. import subprocess
  7. parser = argparse.ArgumentParser(description="Run the Pagure worker")
  8. parser.add_argument(
  9. "--config",
  10. "-c",
  11. dest="config",
  12. help="Configuration file to use for pagure.",
  13. )
  14. parser.add_argument(
  15. "--debug",
  16. dest="debug",
  17. action="store_true",
  18. default=False,
  19. help="Expand the level of data returned.",
  20. )
  21. parser.add_argument(
  22. "--queue",
  23. dest="queue",
  24. default=None,
  25. help="Name of the queue to run the worker against.",
  26. )
  27. parser.add_argument(
  28. "--tasks",
  29. dest="tasks",
  30. default="pagure.lib.tasks",
  31. help="Class used by the workers.",
  32. )
  33. parser.add_argument(
  34. "--noinfo",
  35. dest="noinfo",
  36. action="store_true",
  37. default=False,
  38. help="Reduce the log level.",
  39. )
  40. args = parser.parse_args()
  41. env = os.environ
  42. if args.config:
  43. config = args.config
  44. if not config.startswith("/"):
  45. here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
  46. config = os.path.join(here, config)
  47. env["PAGURE_CONFIG"] = config
  48. cmd = [sys.executable, "-m", "celery", "worker", "-A", args.tasks]
  49. if args.queue:
  50. cmd.extend(["-Q", args.queue])
  51. if args.debug:
  52. cmd.append("--loglevel=debug")
  53. elif args.noinfo:
  54. pass
  55. else:
  56. cmd.append("--loglevel=info")
  57. subp = subprocess.Popen(cmd, env=env or None)
  58. subp.wait()