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

NullPool for the celery worker. #1465

Merged
merged 1 commit into from
Oct 28, 2016
Merged
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
11 changes: 9 additions & 2 deletions caravel/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
app, db, models, utils, dataframe, results_backend)
from caravel.db_engine_specs import LimitMethod
from caravel.jinja_context import process_template
from sqlalchemy.pool import NullPool
QueryStatus = models.QueryStatus

celery_app = celery.Celery(config_source=app.config.get('CELERY_CONFIG'))
Expand Down Expand Up @@ -46,9 +47,15 @@ def create_table_as(sql, table_name, schema=None, override=False):
return exec_sql.format(**locals())


@celery_app.task
def get_sql_results(query_id, return_results=True, store_results=False):
@celery_app.task(bind=True)
def get_sql_results(self, query_id, return_results=True, store_results=False):
"""Executes the sql query returns the results."""

# disable pooling for the celery task to prevent
# MySQL server gone issue.
if not self.request.called_directly:
db.engine.pool = NullPool(db.engine.create)

session = db.session()
session.commit() # HACK
query = session.query(models.Query).filter_by(id=query_id).one()
Expand Down