Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom celeryconfig modules #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ 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** directive 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