[PATCH 5 of 5 WIP] cli: convert 'gearbox celeryd' to 'kallithea-cli celery run'

Thomas De Schampheleire patrickdepinguin at gmail.com
Tue Oct 2 20:42:36 UTC 2018


# HG changeset patch
# User Thomas De Schampheleire <thomas.de_schampheleire at nokia.com>
# Date 1538510861 -7200
#      Tue Oct 02 22:07:41 2018 +0200
# Node ID 62cbc1f96eb9775494294ea269fa94a82838b4f8
# Parent  c822ec47027e8df140b8d1e2256427c0e109074a
cli: convert 'gearbox celeryd' to 'kallithea-cli celery run'

Notes:
- '--' is never explicitly present in the arguments, this is covered by
  click.
- the changes in cmd.run_from_argv are done to get correct help and error
  message output.

diff --git a/docs/setup.rst b/docs/setup.rst
--- a/docs/setup.rst
+++ b/docs/setup.rst
@@ -307,7 +307,7 @@ Celery. So for example setting `BROKER_H
 
 To start the Celery process, run::
 
- gearbox celeryd -c <configfile.ini>
+  kallithea-cli celery run <configfile.ini>
 
 Extra options to the Celery worker can be passed after ``--`` - see ``-- -h``
 for more info.
diff --git a/init.d/celeryd-upstart.conf b/init.d/celeryd-upstart.conf
--- a/init.d/celeryd-upstart.conf
+++ b/init.d/celeryd-upstart.conf
@@ -21,7 +21,7 @@ env USER=hg
 # env GROUP=hg
 
 script
-    COMMAND="/var/hg/.virtualenvs/kallithea/bin/gearbox celeryd -c $APPINI -- --pidfile=$PIDFILE"
+    COMMAND="/var/hg/.virtualenvs/kallithea/bin/kallithea-cli celery run $APPINI -- --pidfile=$PIDFILE"
     if [ -z "$GROUP" ]; then
         exec sudo -u $USER $COMMAND
     else
diff --git a/kallithea/bin/kallithea_cli.py b/kallithea/bin/kallithea_cli.py
--- a/kallithea/bin/kallithea_cli.py
+++ b/kallithea/bin/kallithea_cli.py
@@ -14,6 +14,7 @@
 
 import click
 
+from kallithea.bin.kallithea_cli_celery import celery
 from kallithea.bin.kallithea_cli_config import config
 from kallithea.bin.kallithea_cli_ishell import ishell
 
@@ -22,5 +23,6 @@ def cli():
     """Various commands to set up a Kallithea instance."""
     pass
 
+cli.add_command(celery)
 cli.add_command(config)
 cli.add_command(ishell)
diff --git a/kallithea/lib/paster_commands/celeryd.py b/kallithea/bin/kallithea_cli_celery.py
rename from kallithea/lib/paster_commands/celeryd.py
rename to kallithea/bin/kallithea_cli_celery.py
--- a/kallithea/lib/paster_commands/celeryd.py
+++ b/kallithea/bin/kallithea_cli_celery.py
@@ -1,38 +1,44 @@
 # -*- coding: utf-8 -*-
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-import argparse
+import click
 
 import kallithea
-from kallithea.lib.paster_commands.common import BasePasterCommand
-
-__all__ = ['Command']
+import kallithea.bin.kallithea_cli_util as cli_util
 
-
-class Command(BasePasterCommand):
-    """Kallithea: Celery worker for asynchronous tasks"""
+ at click.group()
+def celery():
+    pass
 
-    # Starts the celery worker using configuration from a paste.deploy
-    # configuration file.
-
-    def take_action(self, args):
-        if not kallithea.CELERY_ON:
-            raise Exception('Please set use_celery = true in .ini config '
-                            'file before running celeryd')
+ at celery.command()
+ at cli_util.auto_setup_app()
+ at click.argument('celery_args', nargs=-1)
+def run(config_file, celery_args):
+    """Start Celery worker(s) for asynchronous tasks
 
-        from kallithea.lib import celerypylons
-        cmd = celerypylons.worker.worker(celerypylons.app)
+    This commands starts the Celery daemon which will spawn workers to handle
+    certain asynchronous tasks for Kallithea.
 
-        celery_args = args.celery_args
-        if '--' in celery_args:
-            celery_args.remove('--')
-
-        return cmd.run_from_argv('kallithea celery worker', celery_args)
+    Any extra arguments you pass to this command will be passed through to
+    Celery. Use '--' before such extra arguments to avoid options to be parsed
+    by this CLI command.
+    """
 
-    def get_parser(self, prog_name):
-        parser = super(Command, self).get_parser(prog_name)
+    if not kallithea.CELERY_ON:
+        raise Exception('Please set use_celery = true in .ini config '
+                        'file before running this command')
 
-        parser.add_argument('celery_args', nargs=argparse.REMAINDER,
-            help="Pass extra options to Celery after a '--' separator",
-            )
-
-        return parser
+    from kallithea.lib import celerypylons
+    cmd = celerypylons.worker.worker(celerypylons.app)
+    return cmd.run_from_argv(cli_util.full_cmd_name(), list(celery_args), 'CONFIG_FILE --')
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -159,7 +159,6 @@ setuptools.setup(
 
     [gearbox.commands]
     cache-keys=kallithea.lib.paster_commands.cache_keys:Command
-    celeryd=kallithea.lib.paster_commands.celeryd:Command
     cleanup-repos=kallithea.lib.paster_commands.cleanup:Command
     install-iis=kallithea.lib.paster_commands.install_iis:Command
     make-index=kallithea.lib.paster_commands.make_index:Command


More information about the kallithea-general mailing list