Skip to content

Commit 13ce23c

Browse files
committed
Support custom celeryconfig modules
1 parent cf8aa80 commit 13ce23c

File tree

7 files changed

+24
-2
lines changed

7 files changed

+24
-2
lines changed

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ If you want to use the standard **celeryconfig** python file you can set the
6464
6565
[celery]
6666
use_celeryconfig = True
67+
celery_config_module = my.custom.celeryconfig
68+
69+
You may also suppress the **celery_config_module** to use the default `"celeryconfig"`
6770

6871
You can get more information for celeryconfig.py here:
6972

pyramid_celery/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def setup_app(app, root, request, registry, closer, ini_location):
7070
)
7171

7272
if asbool(celery_config.get('use_celeryconfig', False)) is True:
73-
config_path = 'celeryconfig'
73+
config_path = celery_config.get('celery_config_module', 'celeryconfig')
7474
celery_app.config_from_object(config_path)
7575
else:
7676
hijack_key = 'worker_hijack_root_logger'

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import sys
32
from setuptools import setup, find_packages
43

54
here = os.path.abspath(os.path.dirname(__file__))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[celery]
2+
use_celeryconfig = true
3+
celery_config_module = custom_celeryconfig.config

tests/custom_celeryconfig/__init__.py

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
BROKER_URL = "redis://localhost:1337/1"

tests/test_celery.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ def test_includeme_use_celeryconfig():
5252
assert celery_app.conf['broker_url'] == 'redis://localhost:1337/0'
5353

5454

55+
@pytest.mark.unit
56+
def test_includeme_use_custom_celeryconfig():
57+
from pyramid_celery import includeme
58+
from pyramid_celery import celery_app
59+
from pyramid import testing
60+
from pyramid.registry import Registry
61+
config = testing.setUp()
62+
config.registry = Registry()
63+
config.registry.settings = {}
64+
65+
includeme(config)
66+
config.configure_celery('tests/configs/custom_useceleryconfig.ini')
67+
68+
assert celery_app.conf['broker_url'] == 'redis://localhost:1337/1'
69+
70+
5571
@pytest.mark.unit
5672
def test_preload_no_ini():
5773
from pyramid_celery import on_preload_parsed

0 commit comments

Comments
 (0)