celeryd.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #!/usr/bin/env python
  2. """celeryd
  3. .. program:: celeryd
  4. .. cmdoption:: -c, --concurrency
  5. Number of child processes processing the queue. The default
  6. is the number of CPUs available on your system.
  7. .. cmdoption:: -f, --logfile
  8. Path to log file. If no logfile is specified, ``stderr`` is used.
  9. .. cmdoption:: -l, --loglevel
  10. Logging level, choose between ``DEBUG``, ``INFO``, ``WARNING``,
  11. ``ERROR``, ``CRITICAL``, or ``FATAL``.
  12. .. cmdoption:: -n, --hostname
  13. Set custom hostname.
  14. .. cmdoption:: -B, --beat
  15. Also run the ``celerybeat`` periodic task scheduler. Please note that
  16. there must only be one instance of this service.
  17. .. cmdoption:: -Q, --queues
  18. List of queues to enable for this worker, separated by comma.
  19. By default all configured queues are enabled.
  20. Example: ``-Q video,image``
  21. .. cmdoption:: -I, --include
  22. Comma separated list of additional modules to import.
  23. Example: -I foo.tasks,bar.tasks
  24. .. cmdoption:: -s, --schedule
  25. Path to the schedule database if running with the ``-B`` option.
  26. Defaults to ``celerybeat-schedule``. The extension ".db" will be
  27. appended to the filename.
  28. .. cmdoption:: -E, --events
  29. Send events that can be captured by monitors like ``celerymon``.
  30. .. cmdoption:: --purge, --discard
  31. Discard all waiting tasks before the daemon is started.
  32. **WARNING**: This is unrecoverable, and the tasks will be
  33. deleted from the messaging server.
  34. .. cmdoption:: --time-limit
  35. Enables a hard time limit (in seconds) for tasks.
  36. .. cmdoption:: --soft-time-limit
  37. Enables a soft time limit (in seconds) for tasks.
  38. .. cmdoption:: --maxtasksperchild
  39. Maximum number of tasks a pool worker can execute before it's
  40. terminated and replaced by a new worker.
  41. """
  42. import multiprocessing
  43. from celery import __version__
  44. from celery.bin.base import Command, Option
  45. class WorkerCommand(Command):
  46. namespace = "celeryd"
  47. enable_config_from_cmdline = True
  48. def run(self, *args, **kwargs):
  49. kwargs.pop("app", None)
  50. return self.app.Worker(**kwargs).run()
  51. def get_options(self):
  52. conf = self.app.conf
  53. return (
  54. Option('-c', '--concurrency',
  55. default=conf.CELERYD_CONCURRENCY,
  56. action="store", dest="concurrency", type="int",
  57. help="Number of child processes processing the queue."),
  58. Option('--purge', '--discard', default=False,
  59. action="store_true", dest="discard",
  60. help="Discard all waiting tasks before the server is"
  61. "started. WARNING: There is no undo operation "
  62. "and the tasks will be deleted."),
  63. Option('-f', '--logfile', default=conf.CELERYD_LOG_FILE,
  64. action="store", dest="logfile",
  65. help="Path to log file."),
  66. Option('-l', '--loglevel', default=conf.CELERYD_LOG_LEVEL,
  67. action="store", dest="loglevel",
  68. help="Choose between DEBUG/INFO/WARNING/ERROR/CRITICAL"),
  69. Option('-n', '--hostname', default=None,
  70. action="store", dest="hostname",
  71. help="Set custom host name. E.g. 'foo.example.com'."),
  72. Option('-B', '--beat', default=False,
  73. action="store_true", dest="run_clockservice",
  74. help="Also run the celerybeat periodic task scheduler. "
  75. "NOTE: Only one instance of celerybeat must be"
  76. "running at any one time."),
  77. Option('-s', '--schedule',
  78. default=conf.CELERYBEAT_SCHEDULE_FILENAME,
  79. action="store", dest="schedule",
  80. help="Path to the schedule database if running with the -B "
  81. "option. The extension '.db' will be appended to the "
  82. "filename. Default: %s" % (
  83. conf.CELERYBEAT_SCHEDULE_FILENAME, )),
  84. Option('-S', '--statedb', default=conf.CELERYD_STATE_DB,
  85. action="store", dest="db",
  86. help="Path to the state database. The extension '.db' will "
  87. "be appended to the filename. Default: %s" % (
  88. conf.CELERYD_STATE_DB, )),
  89. Option('-E', '--events', default=conf.CELERY_SEND_EVENTS,
  90. action="store_true", dest="events",
  91. help="Send events so the worker can be monitored by "
  92. "celeryev, celerymon and other monitors.."),
  93. Option('--time-limit',
  94. default=conf.CELERYD_TASK_TIME_LIMIT,
  95. action="store", type="int", dest="task_time_limit",
  96. help="Enables a hard time limit (in seconds) for tasks."),
  97. Option('--soft-time-limit',
  98. default=conf.CELERYD_TASK_SOFT_TIME_LIMIT,
  99. action="store", type="int", dest="task_soft_time_limit",
  100. help="Enables a soft time limit (in seconds) for tasks."),
  101. Option('--maxtasksperchild',
  102. default=conf.CELERYD_MAX_TASKS_PER_CHILD,
  103. action="store", type="int", dest="max_tasks_per_child",
  104. help="Maximum number of tasks a pool worker can execute"
  105. "before it's terminated and replaced by a new worker."),
  106. Option('--queues', '-Q', default=[],
  107. action="store", dest="queues",
  108. help="Comma separated list of queues to consume from. "
  109. "By default all configured queues are used. "
  110. "Example: -Q video,image"),
  111. Option('--include', '-I', default=[],
  112. action="store", dest="include",
  113. help="Comma separated list of additional modules to import. "
  114. "Example: -I foo.tasks,bar.tasks"),
  115. )
  116. def main():
  117. multiprocessing.freeze_support()
  118. worker = WorkerCommand()
  119. worker.execute_from_commandline()
  120. if __name__ == "__main__":
  121. main()