Skip to content

Instantly share code, notes, and snippets.

@rinaldo-rex
Created June 11, 2019 09:29
Show Gist options
  • Save rinaldo-rex/d4a917beae1ee941a635a8c5a9dcf7c9 to your computer and use it in GitHub Desktop.
Save rinaldo-rex/d4a917beae1ee941a635a8c5a9dcf7c9 to your computer and use it in GitHub Desktop.
Celery worker for application factory
"""The celery worker has to be started to handle the tasks of celery.
This pattern is followed because we're instantiating the flask application through
flask's application factory. The context of the application is required.
"""
from project import create_app # Flask application factory is used.
from project import celery # This is the celery instance that needs to be instantiated when a flask app is created.
import logging
logger = logging.getLogger('celery')
logger.setLevel(logging.DEBUG)
logger.propagate = True # To show the logs on celery worker
app = create_app()
app.app_context().push() # This is the most important thing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment