commands.py
82 lines
| 2.4 KiB
| text/x-python
|
PythonLexer
r785 | from rhodecode.lib.utils import BasePasterCommand, Command | |||
r1002 | from celery.app import app_or_default | |||
from celery.bin import camqadm, celerybeat, celeryd, celeryev | ||||
r776 | ||||
__all__ = ['CeleryDaemonCommand', 'CeleryBeatCommand', | ||||
'CAMQPAdminCommand', 'CeleryEventCommand'] | ||||
r1002 | class CeleryCommand(BasePasterCommand): | |||
"""Abstract class implements run methods needed for celery | ||||
Starts the celery worker that uses a paste.deploy configuration | ||||
file. | ||||
""" | ||||
def update_parser(self): | ||||
""" | ||||
Abstract method. Allows for the class's parser to be updated | ||||
before the superclass's `run` method is called. Necessary to | ||||
allow options/arguments to be passed through to the underlying | ||||
celery command. | ||||
""" | ||||
cmd = self.celery_command(app_or_default()) | ||||
for x in cmd.get_options(): | ||||
self.parser.add_option(x) | ||||
def command(self): | ||||
cmd = self.celery_command(app_or_default()) | ||||
return cmd.run(**vars(self.options)) | ||||
class CeleryDaemonCommand(CeleryCommand): | ||||
r776 | """Start the celery worker | |||
Starts the celery worker that uses a paste.deploy configuration | ||||
file. | ||||
""" | ||||
usage = 'CONFIG_FILE [celeryd options...]' | ||||
summary = __doc__.splitlines()[0] | ||||
description = "".join(__doc__.splitlines()[2:]) | ||||
parser = Command.standard_parser(quiet=True) | ||||
r1002 | celery_command = celeryd.WorkerCommand | |||
r776 | ||||
r1002 | class CeleryBeatCommand(CeleryCommand): | |||
r776 | """Start the celery beat server | |||
Starts the celery beat server using a paste.deploy configuration | ||||
file. | ||||
""" | ||||
usage = 'CONFIG_FILE [celerybeat options...]' | ||||
summary = __doc__.splitlines()[0] | ||||
description = "".join(__doc__.splitlines()[2:]) | ||||
parser = Command.standard_parser(quiet=True) | ||||
r1002 | celery_command = celerybeat.BeatCommand | |||
r776 | ||||
r1002 | class CAMQPAdminCommand(CeleryCommand): | |||
r776 | """CAMQP Admin | |||
CAMQP celery admin tool. | ||||
""" | ||||
usage = 'CONFIG_FILE [camqadm options...]' | ||||
summary = __doc__.splitlines()[0] | ||||
description = "".join(__doc__.splitlines()[2:]) | ||||
parser = Command.standard_parser(quiet=True) | ||||
r1002 | celery_command = camqadm.AMQPAdminCommand | |||
r776 | ||||
r1002 | class CeleryEventCommand(CeleryCommand): | |||
"""Celery event command. | ||||
r776 | ||||
Capture celery events. | ||||
""" | ||||
usage = 'CONFIG_FILE [celeryev options...]' | ||||
summary = __doc__.splitlines()[0] | ||||
description = "".join(__doc__.splitlines()[2:]) | ||||
parser = Command.standard_parser(quiet=True) | ||||
r1002 | celery_command = celeryev.EvCommand | |||