Skip to content

Commit

Permalink
Support custom celeryconfig modules
Browse files Browse the repository at this point in the history
  • Loading branch information
phrfpeixoto committed Mar 3, 2021
1 parent cf8aa80 commit 13ce23c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ If you want to use the standard **celeryconfig** python file you can set the
[celery]
use_celeryconfig = True
celery_config_module = my.custom.celeryconfig
You may also suppress the **celery_config_module** to use the default `"celeryconfig"`

You can get more information for celeryconfig.py here:

Expand Down
2 changes: 1 addition & 1 deletion pyramid_celery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def setup_app(app, root, request, registry, closer, ini_location):
)

if asbool(celery_config.get('use_celeryconfig', False)) is True:
config_path = 'celeryconfig'
config_path = celery_config.get('celery_config_module', 'celeryconfig')
celery_app.config_from_object(config_path)
else:
hijack_key = 'worker_hijack_root_logger'
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import sys
from setuptools import setup, find_packages

here = os.path.abspath(os.path.dirname(__file__))
Expand Down
3 changes: 3 additions & 0 deletions tests/configs/custom_useceleryconfig.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[celery]
use_celeryconfig = true
celery_config_module = custom_celeryconfig.config
Empty file.
1 change: 1 addition & 0 deletions tests/custom_celeryconfig/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BROKER_URL = "redis://localhost:1337/1"
16 changes: 16 additions & 0 deletions tests/test_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ def test_includeme_use_celeryconfig():
assert celery_app.conf['broker_url'] == 'redis://localhost:1337/0'


@pytest.mark.unit
def test_includeme_use_custom_celeryconfig():
from pyramid_celery import includeme
from pyramid_celery import celery_app
from pyramid import testing
from pyramid.registry import Registry
config = testing.setUp()
config.registry = Registry()
config.registry.settings = {}

includeme(config)
config.configure_celery('tests/configs/custom_useceleryconfig.ini')

assert celery_app.conf['broker_url'] == 'redis://localhost:1337/1'


@pytest.mark.unit
def test_preload_no_ini():
from pyramid_celery import on_preload_parsed
Expand Down

0 comments on commit 13ce23c

Please sign in to comment.