-
Notifications
You must be signed in to change notification settings - Fork 553
UN-2798 [FIX] Fix WorkflowFileExecution stuck in EXECUTING status due to database connection errors #1524
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
base: main
Are you sure you want to change the base?
UN-2798 [FIX] Fix WorkflowFileExecution stuck in EXECUTING status due to database connection errors #1524
Changes from 5 commits
86cff59
f0979aa
78a8660
7c0d03c
0eeae21
e606f1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
import os | ||
from urllib.parse import quote_plus | ||
|
||
from django.conf import settings | ||
|
||
from backend.celery_db_retry import get_celery_db_engine_options, should_use_builtin_retry | ||
|
||
|
||
class CeleryConfig: | ||
"""Specifies celery configuration | ||
"""Specifies celery configuration with hybrid retry support. | ||
|
||
Supports both custom retry (via patching) and Celery's built-in retry | ||
based on CELERY_USE_BUILTIN_RETRY environment variable. | ||
|
||
Refer https://docs.celeryq.dev/en/stable/userguide/configuration.html | ||
""" | ||
|
@@ -31,3 +37,32 @@ class CeleryConfig: | |
beat_scheduler = "django_celery_beat.schedulers:DatabaseScheduler" | ||
|
||
task_acks_late = True | ||
|
||
# Database backend engine options for PgBouncer compatibility | ||
result_backend_transport_options = get_celery_db_engine_options() | ||
|
||
Comment on lines
+44
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainConfirm Celery picks up engine options for SQLAlchemy backend.
Run: If your version differs, we may need to adjust the config key or option names. 🏁 Script executed: #!/bin/bash
# Inspect Celery DatabaseBackend to confirm it uses `result_backend_transport_options`
python - <<'PY'
import inspect
from celery.backends import database
print("DatabaseBackend.create_backend method:\n")
print(inspect.getsource(database.DatabaseBackend.__init__))
PY Length of output: 118 🏁 Script executed: #!/bin/bash
# Locate Celery dependency and its pinned version in the repository
grep -R "celery" -n requirements*.txt pyproject.toml setup.py Length of output: 255 🏁 Script executed: #!/bin/bash
# Install the pinned Celery version and inspect DatabaseBackend for transport options handling
pip install celery==5.3.4 >/dev/null 2>&1
python - <<'PY'
import inspect
from celery.backends.database import DatabaseBackend
print("Signature of DatabaseBackend.__init__:\n")
print(inspect.signature(DatabaseBackend.__init__), "\n")
print("Source snippet around engine creation in DatabaseBackend:\n")
src = inspect.getsource(DatabaseBackend)
for line in src.splitlines():
if "create_engine" in line or "transport_options" in line:
print(line)
PY Length of output: 437 🏁 Script executed: #!/bin/bash
# Install Celery and SQLAlchemy to enable DatabaseBackend inspection
pip install celery==5.3.4 sqlalchemy >/dev/null 2>&1
python - <<'PY'
import inspect
from celery.backends.database import DatabaseBackend
print("Signature of DatabaseBackend.__init__:\n", inspect.signature(DatabaseBackend.__init__), "\n")
source = inspect.getsource(DatabaseBackend)
print("Lines containing engine creation or transport options:\n")
for line in source.splitlines():
if "create_engine" in line or "transport_options" in line:
print(line)
PY Length of output: 157 🏁 Script executed: #!/bin/bash
# Print the source of DatabaseBackend.__init__ to inspect engine_options usage
python - <<'PY'
import inspect
from celery.backends.database import DatabaseBackend
print(inspect.getsource(DatabaseBackend.__init__))
PY Length of output: 1243 Use 🤖 Prompt for AI Agents
|
||
# Hybrid retry configuration - built-in vs custom | ||
if should_use_builtin_retry(): | ||
# Use Celery's built-in database backend retry | ||
result_backend_always_retry = ( | ||
os.environ.get("CELERY_RESULT_BACKEND_ALWAYS_RETRY", "true").lower() == "true" | ||
) | ||
result_backend_max_retries = int( | ||
os.environ.get("CELERY_RESULT_BACKEND_MAX_RETRIES", "3") | ||
) | ||
result_backend_base_sleep_between_retries_ms = int( | ||
os.environ.get("CELERY_RESULT_BACKEND_BASE_SLEEP_BETWEEN_RETRIES_MS", "1000") | ||
) | ||
result_backend_max_sleep_between_retries_ms = int( | ||
os.environ.get("CELERY_RESULT_BACKEND_MAX_SLEEP_BETWEEN_RETRIES_MS", "30000") | ||
) | ||
|
||
print( | ||
f"[Celery Config] Using built-in retry: max_retries={result_backend_max_retries}, " | ||
) | ||
print( | ||
f"base_sleep={result_backend_base_sleep_between_retries_ms}ms, max_sleep={result_backend_max_sleep_between_retries_ms}ms" | ||
) | ||
else: | ||
# Custom retry is handled by patch_celery_database_backend() | ||
print("[Celery Config] Using custom retry system (patching enabled)") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix import path for retry helpers.
File resides under
backend/backend/
, so the import should referencebackend.backend.celery_db_retry
. Current path will fail at runtime.Apply this diff:
📝 Committable suggestion
🤖 Prompt for AI Agents