changeset 6800:df5a67678b96

celeryd: let the gearbox command use db session as most other gearbox commands do 304aae43194c changed the common gearbox wrapper so make_app_without_logging only was run for commands tagged as requires_db_session. That broke celeryd - even a plain 'gearbox celeryd -c my.ini' would fail on the safety check in celerypylons asserting on tg.config having 'celery.imports' configuration. The gearbox celeryd command did not really require a db session - it just required app configuration so it could create db sessions on the fly. To to get the missing make_app_without_logging invocation back, set requires_db_session (the default for our gearbox commands). requires_db_session not only calls make_app_without_logging (which undo the effect from 304aae43194c), it also calls setup_cache_regions, engine_from_config, and init_model. These were also invoked explicitly in celeryd code - these double invocations are dropped too. Also, make_app_without_logging will call into tg and thus invoke the setup_configuration hook which will set kallithea.CELERY_ON and call load_rcextensions. The celeryd code for doing that is thus dropped.
author Mads Kiilerich <mads@kiilerich.com>
date Sat, 12 Aug 2017 17:55:58 +0200
parents 5aa9fa97306f
children 970ee88be388
files kallithea/lib/celerylib/__init__.py kallithea/lib/celerylib/tasks.py kallithea/lib/paster_commands/celeryd.py
diffstat 3 files changed, 3 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/celerylib/__init__.py	Sat Aug 12 17:40:01 2017 +0200
+++ b/kallithea/lib/celerylib/__init__.py	Sat Aug 12 17:55:58 2017 +0200
@@ -121,9 +121,6 @@
 
 
 def get_session():
-    if CELERY_ON:
-        engine = engine_from_config(config, 'sqlalchemy.')
-        init_model(engine)
     sa = meta.Session()
     return sa
 
--- a/kallithea/lib/celerylib/tasks.py	Sat Aug 12 17:40:01 2017 +0200
+++ b/kallithea/lib/celerylib/tasks.py	Sat Aug 12 17:55:58 2017 +0200
@@ -41,7 +41,7 @@
 from kallithea.lib import celerylib
 from kallithea.lib.helpers import person
 from kallithea.lib.rcmail.smtp_mailer import SmtpMailer
-from kallithea.lib.utils import setup_cache_regions, action_logger
+from kallithea.lib.utils import action_logger
 from kallithea.lib.utils2 import str2bool
 from kallithea.lib.vcs.utils import author_email
 from kallithea.lib.compat import json, OrderedDict
@@ -50,8 +50,6 @@
 from kallithea.model.db import Statistics, RepoGroup, Repository, User
 
 
-setup_cache_regions(config)  # pragma: no cover
-
 __all__ = ['whoosh_index', 'get_commits_stats', 'send_email']
 
 
--- a/kallithea/lib/paster_commands/celeryd.py	Sat Aug 12 17:40:01 2017 +0200
+++ b/kallithea/lib/paster_commands/celeryd.py	Sat Aug 12 17:55:58 2017 +0200
@@ -4,7 +4,6 @@
 
 import kallithea
 from kallithea.lib.paster_commands.common import BasePasterCommand
-from kallithea.lib.utils import load_rcextensions
 from kallithea.lib.utils2 import str2bool
 
 __all__ = ['Command']
@@ -16,21 +15,12 @@
     # Starts the celery worker using configuration from a paste.deploy
     # configuration file.
 
-    requires_db_session = False # will start session on demand
-
     def take_action(self, args):
-        from kallithea.lib import celerypylons
-        try:
-            CELERY_ON = str2bool(self.config['app_conf'].get('use_celery'))
-        except KeyError:
-            CELERY_ON = False
-
-        if not CELERY_ON:
+        if not kallithea.CELERY_ON:
             raise Exception('Please set use_celery = true in .ini config '
                             'file before running celeryd')
-        kallithea.CELERY_ON = CELERY_ON
 
-        load_rcextensions(self.config['here'])
+        from kallithea.lib import celerypylons
         cmd = celerypylons.worker.worker(celerypylons.app.app_or_default())
 
         celery_args = args.celery_args