runworker.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env python
  2. from __future__ import unicode_literals
  3. # These two lines are needed to run on EL6
  4. __requires__ = ['SQLAlchemy >= 0.8', 'jinja2 >= 2.4']
  5. import pkg_resources
  6. import argparse
  7. import sys
  8. import os
  9. import subprocess
  10. parser = argparse.ArgumentParser(
  11. description='Run the Pagure worker')
  12. parser.add_argument(
  13. '--config', '-c', dest='config',
  14. help='Configuration file to use for pagure.')
  15. parser.add_argument(
  16. '--debug', dest='debug', action='store_true',
  17. default=False,
  18. help='Expand the level of data returned.')
  19. parser.add_argument(
  20. '--noinfo', dest='noinfo', action='store_true',
  21. default=False,
  22. help='Reduce the log level.')
  23. args = parser.parse_args()
  24. env = {}
  25. if args.config:
  26. config = args.config
  27. if not config.startswith('/'):
  28. here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
  29. config = os.path.join(here, config)
  30. env['PAGURE_CONFIG'] = config
  31. cmd = [
  32. sys.executable, '-m', 'celery', 'worker', '-A', 'pagure.lib.tasks'
  33. ]
  34. if args.debug:
  35. cmd.append('--loglevel=debug')
  36. elif args.noinfo:
  37. pass
  38. else:
  39. cmd.append('--loglevel=info')
  40. subp = subprocess.Popen(cmd, env=env or None)
  41. subp.wait()