Skip to content

Commit

Permalink
NullPool for the celery worker. (#1465)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkyryliuk authored Oct 28, 2016
1 parent d2826ab commit 07a7736
Showing 1 changed file with 9 additions and 2 deletions.
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

0 comments on commit 07a7736

Please sign in to comment.