Skip to content

Instantly share code, notes, and snippets.

@sirn
Created December 25, 2013 17:37
Show Gist options
  • Save sirn/8125185 to your computer and use it in GitHub Desktop.
Save sirn/8125185 to your computer and use it in GitHub Desktop.
Celery integration with Pyramid
from .tasks import celery, configure_celery
# ...
def main(global_config, **settings): # pragma: no cover
""" This function returns a Pyramid WSGI application.
"""
# ...
configure_celery(celery, settings)
# ...
import os
import sys
from pyramid.paster import bootstrap
from app.tasks import celery, configure_celery
def main(argv=sys.argv):
if not len(argv) >= 2:
sys.stderr.write("Usage: %s config\n" % os.path.basename(argv[0]))
sys.stderr.write("Configuration file not present.\n")
sys.exit(1)
app = bootstrap(argv[1])
celery_app = configure_celery(celery, app['registry'].settings)
celery_app.start(argv[:1] + argv[2:]) # Remove argv[1].
# ...
setup(
name='app',
# ...
entry_points="""\
[console_scripts]
pycelery = app.celery:main
""",
)
from celery import Celery
celery = Celery()
def configure_celery(_celery, settings):
_celery.conf.update(
BROKER_URL=settings['celery.broker'],
CELERY_RESULT_BACKEND=settings['celery.broker'])
return _celery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment