mirror of
https://github.com/apache/superset.git
synced 2026-04-19 16:14:52 +00:00
fix(celery): Reset DB connection pools for forked worker processes (#13350)
* Reset sqlalchemy connection pool on celery process fork * Fix race condition with async chart loading state * pylint: ignore * prettier
This commit is contained in:
@@ -19,13 +19,16 @@
|
||||
This is the main entrypoint used by Celery workers. As such,
|
||||
it needs to call create_app() in order to initialize things properly
|
||||
"""
|
||||
from typing import Any
|
||||
|
||||
from celery.signals import worker_process_init
|
||||
|
||||
# Superset framework imports
|
||||
from superset import create_app
|
||||
from superset.extensions import celery_app
|
||||
from superset.extensions import celery_app, db
|
||||
|
||||
# Init the Flask app / configure everything
|
||||
create_app()
|
||||
flask_app = create_app()
|
||||
|
||||
# Need to import late, as the celery_app will have been setup by "create_app()"
|
||||
# pylint: disable=wrong-import-position, unused-import
|
||||
@@ -33,3 +36,10 @@ from . import cache, schedules, scheduler # isort:skip
|
||||
|
||||
# Export the celery app globally for Celery (as run on the cmd line) to find
|
||||
app = celery_app
|
||||
|
||||
|
||||
@worker_process_init.connect
|
||||
def reset_db_connection_pool(**kwargs: Any) -> None: # pylint: disable=unused-argument
|
||||
with flask_app.app_context():
|
||||
# https://docs.sqlalchemy.org/en/14/core/connections.html#engine-disposal
|
||||
db.engine.dispose()
|
||||
|
||||
Reference in New Issue
Block a user