celerybeat.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env python
  2. """celerybeat
  3. .. program:: celerybeat
  4. .. cmdoption:: -s, --schedule
  5. Path to the schedule database. Defaults to `celerybeat-schedule`.
  6. The extension ".db" will be appended to the filename.
  7. .. cmdoption:: -S, --scheduler
  8. Scheduler class to use. Default is celery.beat.PersistentScheduler
  9. .. cmdoption:: -f, --logfile
  10. Path to log file. If no logfile is specified, `stderr` is used.
  11. .. cmdoption:: -l, --loglevel
  12. Logging level, choose between `DEBUG`, `INFO`, `WARNING`,
  13. `ERROR`, `CRITICAL`, or `FATAL`.
  14. """
  15. from __future__ import with_statement
  16. from __future__ import absolute_import
  17. from functools import partial
  18. from ..platforms import detached
  19. from .base import Command, Option, daemon_options
  20. class BeatCommand(Command):
  21. supports_args = False
  22. def run(self, detach=False, logfile=None, pidfile=None, uid=None,
  23. gid=None, umask=None, working_directory=None, **kwargs):
  24. kwargs.pop("app", None)
  25. beat = partial(self.app.Beat,
  26. logfile=logfile, pidfile=pidfile, **kwargs)
  27. workdir = working_directory
  28. if detach:
  29. with detached(logfile, pidfile, uid, gid, umask, workdir):
  30. return beat().run()
  31. else:
  32. return beat().run()
  33. def get_options(self):
  34. conf = self.app.conf
  35. return (
  36. Option('--detach',
  37. default=False, action="store_true", dest="detach",
  38. help="Detach and run in the background."),
  39. Option('-s', '--schedule',
  40. default=conf.CELERYBEAT_SCHEDULE_FILENAME,
  41. action="store", dest="schedule",
  42. help="Path to the schedule database. The extension "
  43. "'.db' will be appended to the filename. Default: %s" % (
  44. conf.CELERYBEAT_SCHEDULE_FILENAME, )),
  45. Option('--max-interval',
  46. default=3600.0, type="float", dest="max_interval",
  47. help="Max. seconds to sleep between schedule iterations."),
  48. Option('-S', '--scheduler',
  49. default=None,
  50. action="store", dest="scheduler_cls",
  51. help="Scheduler class. Default is "
  52. "celery.beat.PersistentScheduler"),
  53. Option('-l', '--loglevel',
  54. default=conf.CELERYBEAT_LOG_LEVEL,
  55. action="store", dest="loglevel",
  56. help="Loglevel. One of DEBUG/INFO/WARNING/ERROR/CRITICAL."),
  57. ) + daemon_options(default_pidfile="celerybeat.pid",
  58. default_logfile=conf.CELERYBEAT_LOG_FILE)
  59. def main():
  60. beat = BeatCommand()
  61. beat.execute_from_commandline()
  62. if __name__ == "__main__": # pragma: no cover
  63. main()