changeset 7417:1d539bb18165

cli: convert 'gearbox celeryd' into 'kallithea-cli celery-run' Note: - '--' is never explicitly present in the arguments when using Click. The click parser will take care of '--' as separator between dash-dash-arguments and positional arguments, following standard UNIX conventions.
author Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
date Sun, 18 Nov 2018 20:02:17 +0100
parents 502b9bd0a24d
children 0f9e7dbfa5d2
files docs/setup.rst init.d/celeryd-upstart.conf kallithea/bin/kallithea_cli.py kallithea/bin/kallithea_cli_celery.py kallithea/lib/paster_commands/celeryd.py setup.py
diffstat 6 files changed, 42 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/docs/setup.rst	Sun Nov 18 20:02:17 2018 +0100
+++ b/docs/setup.rst	Sun Nov 18 20:02:17 2018 +0100
@@ -307,7 +307,7 @@
 
 To start the Celery process, run::
 
-  gearbox celeryd -c my.ini
+  kallithea-cli celery-run -c my.ini
 
 Extra options to the Celery worker can be passed after ``--`` - see ``-- -h``
 for more info.
--- a/init.d/celeryd-upstart.conf	Sun Nov 18 20:02:17 2018 +0100
+++ b/init.d/celeryd-upstart.conf	Sun Nov 18 20:02:17 2018 +0100
@@ -21,7 +21,7 @@
 # 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 -c $APPINI -- --pidfile=$PIDFILE"
     if [ -z "$GROUP" ]; then
         exec sudo -u $USER $COMMAND
     else
--- a/kallithea/bin/kallithea_cli.py	Sun Nov 18 20:02:17 2018 +0100
+++ b/kallithea/bin/kallithea_cli.py	Sun Nov 18 20:02:17 2018 +0100
@@ -16,6 +16,7 @@
 from kallithea.bin.kallithea_cli_base import cli
 
 # import commands (they will add themselves to the 'cli' object)
+import kallithea.bin.kallithea_cli_celery
 import kallithea.bin.kallithea_cli_config
 import kallithea.bin.kallithea_cli_db
 import kallithea.bin.kallithea_cli_extensions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kallithea/bin/kallithea_cli_celery.py	Sun Nov 18 20:02:17 2018 +0100
@@ -0,0 +1,39 @@
+# -*- 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 click
+import kallithea.bin.kallithea_cli_base as cli_base
+
+import kallithea
+
+@cli_base.register_command(config_file_initialize_app=True)
+@click.argument('celery_args', nargs=-1)
+def celery_run(celery_args):
+    """Start Celery worker(s) for asynchronous tasks.
+
+    This commands starts the Celery daemon which will spawn workers to handle
+    certain asynchronous tasks for Kallithea.
+
+    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.
+    """
+
+    if not kallithea.CELERY_ON:
+        raise Exception('Please set use_celery = true in .ini config '
+                        'file before running this command')
+
+    from kallithea.lib import celerypylons
+    cmd = celerypylons.worker.worker(celerypylons.app)
+    return cmd.run_from_argv('kallithea celery worker', celery_args)
--- a/kallithea/lib/paster_commands/celeryd.py	Sun Nov 18 20:02:17 2018 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-# -*- coding: utf-8 -*-
-
-import argparse
-
-import kallithea
-from kallithea.lib.paster_commands.common import BasePasterCommand
-
-__all__ = ['Command']
-
-
-class Command(BasePasterCommand):
-    """Kallithea: Celery worker for asynchronous tasks"""
-
-    # 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')
-
-        from kallithea.lib import celerypylons
-        cmd = celerypylons.worker.worker(celerypylons.app)
-
-        celery_args = args.celery_args
-        if '--' in celery_args:
-            celery_args.remove('--')
-
-        return cmd.run_from_argv('kallithea celery worker', celery_args)
-
-    def get_parser(self, prog_name):
-        parser = super(Command, self).get_parser(prog_name)
-
-        parser.add_argument('celery_args', nargs=argparse.REMAINDER,
-            help="Pass extra options to Celery after a '--' separator",
-            )
-
-        return parser
--- a/setup.py	Sun Nov 18 20:02:17 2018 +0100
+++ b/setup.py	Sun Nov 18 20:02:17 2018 +0100
@@ -159,7 +159,6 @@
     main = kallithea.config.middleware:make_app
 
     [gearbox.commands]
-    celeryd=kallithea.lib.paster_commands.celeryd:Command
     upgrade-db=kallithea.lib.dbmigrate:UpgradeDb
     """,
 )