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

Make sure Flask app created in Celery's worker process #3465

Merged
merged 2 commits into from
Feb 25, 2019
Merged
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
8 changes: 0 additions & 8 deletions redash/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,3 @@ def create_app(load_admin=True):
users.init_app(app)

return app


def safe_create_app():
"""Return current_app or create a new one."""
if current_app:
return current_app

return create_app()
17 changes: 9 additions & 8 deletions redash/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from celery import Celery
from celery.schedules import crontab
from celery.signals import worker_process_init
from redash import safe_create_app, settings
from redash import create_app, settings
from redash.metrics import celery as celery_metrics

celery = Celery('redash',
Expand Down Expand Up @@ -74,14 +74,15 @@ def __call__(self, *args, **kwargs):
# Create Flask app after forking a new worker, to make sure no resources are shared between processes.
@worker_process_init.connect
def init_celery_flask_app(**kwargs):
app = safe_create_app()
app = create_app()
app.app_context().push()


# Commented until https://github.com/getredash/redash/issues/3466 is implemented.
# Hook for extensions to add periodic tasks.
@celery.on_after_configure.connect
def add_periodic_tasks(sender, **kwargs):
app = safe_create_app()
periodic_tasks = getattr(app, 'periodic_tasks', {})
for params in periodic_tasks.values():
sender.add_periodic_task(**params)
# @celery.on_after_configure.connect
# def add_periodic_tasks(sender, **kwargs):
# app = safe_create_app()
# periodic_tasks = getattr(app, 'periodic_tasks', {})
# for params in periodic_tasks.values():
# sender.add_periodic_task(**params)