##// END OF EJS Templates
celery: upgrade to Celery 4...
Mads Kiilerich -
r8137:f8f50d3b default
parent child Browse files
Show More
@@ -250,6 +250,7 b' ssh_enabled = false'
250 ### CELERY CONFIG ####
250 ### CELERY CONFIG ####
251 ####################################
251 ####################################
252
252
253 ## Note: Celery doesn't support Windows.
253 use_celery = false
254 use_celery = false
254
255
255 ## Example: use the message queue on the local virtual host 'kallitheavhost' as the RabbitMQ user 'kallithea':
256 ## Example: use the message queue on the local virtual host 'kallitheavhost' as the RabbitMQ user 'kallithea':
@@ -332,11 +332,11 b' To enable it, simply set::'
332
332
333 use_celery = true
333 use_celery = true
334
334
335 and add or change the ``celery.*`` and ``broker.*`` configuration variables.
335 and add or change the ``celery.*`` configuration variables.
336
336
337 Remember that the ini files use the format with '.' and not with '_' like
337 Configuration settings are prefixed with 'celery.', so for example setting
338 Celery. So for example setting `BROKER_HOST` in Celery means setting
338 `broker_url` in Celery means setting `celery.broker_url` in the configuration
339 `broker.host` in the configuration file.
339 file.
340
340
341 To start the Celery process, run::
341 To start the Celery process, run::
342
342
@@ -23,11 +23,24 b' import kallithea'
23
23
24
24
25 class CeleryConfig(object):
25 class CeleryConfig(object):
26 CELERY_IMPORTS = ['kallithea.lib.celerylib.tasks']
26 imports = ['kallithea.lib.celerylib.tasks']
27 CELERY_ACCEPT_CONTENT = ['json']
27 task_always_eager = False
28 CELERY_RESULT_SERIALIZER = 'json'
28
29 CELERY_TASK_SERIALIZER = 'json'
29 # map from Kallithea .ini Celery 3 config names to Celery 4 config names
30 CELERY_ALWAYS_EAGER = False
30 celery3_compat = {
31 'broker.url': 'broker_url',
32 'celery.accept.content': 'accept_content',
33 'celery.always.eager': 'task_always_eager',
34 'celery.amqp.task.result.expires': 'result_expires',
35 'celeryd.concurrency': 'worker_concurrency',
36 'celeryd.max.tasks.per.child': 'worker_max_tasks_per_child',
37 #'celery.imports' ends up unchanged
38 'celery.result.backend': 'result_backend',
39 'celery.result.serializer': 'result_serializer',
40 'celery.task.serializer': 'task_serializer',
41 }
42
43 list_config_names = """imports accept_content""".split()
31
44
32
45
33 desupported = set([
46 desupported = set([
@@ -45,18 +58,20 b' def make_celery_config(config):'
45
58
46 celery_config = CeleryConfig()
59 celery_config = CeleryConfig()
47
60
48 PREFIXES = """ADMINS BROKER CASSANDRA CELERYBEAT CELERYD CELERYMON CELERY EMAIL SERVER""".split()
49 LIST_PARAMS = """CELERY_IMPORTS CELERY_ACCEPT_CONTENT""".split()
50
51 for config_key, config_value in sorted(config.items()):
61 for config_key, config_value in sorted(config.items()):
52 if config_key in desupported and config_value:
62 if config_key in desupported and config_value:
53 log.error('Celery configuration setting %r is no longer supported', config_key)
63 log.error('Celery configuration setting %r is no longer supported', config_key)
54 celery_key = config_key.replace('.', '_').upper()
64 celery_key = celery3_compat.get(config_key)
55 if celery_key.split('_', 1)[0] not in PREFIXES:
65 parts = config_key.split('.', 1)
66 if celery_key: # explicit Celery 3 backwards compatibility
67 pass
68 elif parts[0] == 'celery' and len(parts) == 2: # Celery 4 config key
69 celery_key = parts[1]
70 else:
56 continue
71 continue
57 if not isinstance(config_value, str):
72 if not isinstance(config_value, str):
58 continue
73 continue
59 if celery_key in LIST_PARAMS:
74 if celery_key in list_config_names:
60 celery_value = config_value.split()
75 celery_value = config_value.split()
61 elif config_value.isdigit():
76 elif config_value.isdigit():
62 celery_value = int(config_value)
77 celery_value = int(config_value)
@@ -72,6 +87,6 b' def make_app():'
72 """Create celery app from the TurboGears configuration file"""
87 """Create celery app from the TurboGears configuration file"""
73 app = celery.Celery()
88 app = celery.Celery()
74 celery_config = make_celery_config(tg.config)
89 celery_config = make_celery_config(tg.config)
75 kallithea.CELERY_EAGER = celery_config.CELERY_ALWAYS_EAGER
90 kallithea.CELERY_EAGER = celery_config.task_always_eager
76 app.config_from_object(celery_config)
91 app.config_from_object(celery_config)
77 return app
92 return app
@@ -356,6 +356,7 b' ssh_locale = ${ssh_locale}'
356 <%text>### CELERY CONFIG ####</%text>
356 <%text>### CELERY CONFIG ####</%text>
357 <%text>####################################</%text>
357 <%text>####################################</%text>
358
358
359 <%text>## Note: Celery doesn't support Windows.</%text>
359 use_celery = false
360 use_celery = false
360
361
361 <%text>## Example: use the message queue on the local virtual host 'kallitheavhost' as the RabbitMQ user 'kallithea':</%text>
362 <%text>## Example: use the message queue on the local virtual host 'kallitheavhost' as the RabbitMQ user 'kallithea':</%text>
@@ -54,7 +54,7 b' requirements = ['
54 "Mako >= 0.9.1, < 1.2",
54 "Mako >= 0.9.1, < 1.2",
55 "Pygments >= 2.2.0, < 2.6",
55 "Pygments >= 2.2.0, < 2.6",
56 "Whoosh >= 2.7.1, < 2.8",
56 "Whoosh >= 2.7.1, < 2.8",
57 "celery >= 3.1, < 4.0", # TODO: celery 4 doesn't work
57 "celery >= 4.3, < 4.5",
58 "Babel >= 1.3, < 2.9",
58 "Babel >= 1.3, < 2.9",
59 "python-dateutil >= 2.1.0, < 2.9",
59 "python-dateutil >= 2.1.0, < 2.9",
60 "Markdown >= 2.2.1, < 3.2",
60 "Markdown >= 2.2.1, < 3.2",
General Comments 0
You need to be logged in to leave comments. Login now