mirror of
https://gitlab.com/bramw/baserow.git
synced 2025-04-13 16:49:07 +00:00
Merge branch '3528-the-local-cache-is-not-invalidated-properly-in-celery-tasks' into 'develop'
Resolve "The local cache is not invalidated properly in celery tasks" Closes #3528 See merge request baserow/baserow!3310
This commit is contained in:
commit
d9118c0227
3 changed files with 24 additions and 3 deletions
backend/src/baserow
changelog/entries/unreleased/bug
|
@ -1,5 +1,20 @@
|
||||||
from celery import Celery
|
from celery import Celery, signals
|
||||||
|
|
||||||
|
from baserow.core.cache import local_cache
|
||||||
|
|
||||||
app = Celery("baserow")
|
app = Celery("baserow")
|
||||||
app.config_from_object("django.conf:settings", namespace="CELERY")
|
app.config_from_object("django.conf:settings", namespace="CELERY")
|
||||||
app.autodiscover_tasks()
|
app.autodiscover_tasks()
|
||||||
|
|
||||||
|
|
||||||
|
def clear_local_cache(*args, **kwargs):
|
||||||
|
"""
|
||||||
|
Clear the thread-local cache before and after each Celery task to prevent
|
||||||
|
data leakage between tasks running on the same worker thread.
|
||||||
|
"""
|
||||||
|
|
||||||
|
local_cache.clear()
|
||||||
|
|
||||||
|
|
||||||
|
signals.task_prerun.connect(clear_local_cache)
|
||||||
|
signals.task_postrun.connect(clear_local_cache)
|
||||||
|
|
|
@ -3,7 +3,6 @@ from datetime import timedelta
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from baserow.config.celery import app
|
from baserow.config.celery import app
|
||||||
from baserow.core.cache import local_cache
|
|
||||||
from baserow.core.jobs.exceptions import JobCancelled
|
from baserow.core.jobs.exceptions import JobCancelled
|
||||||
from baserow.core.jobs.registries import job_type_registry
|
from baserow.core.jobs.registries import job_type_registry
|
||||||
from baserow.core.sentry import setup_user_in_sentry
|
from baserow.core.sentry import setup_user_in_sentry
|
||||||
|
@ -15,7 +14,6 @@ from baserow.core.telemetry.utils import setup_user_in_baggage_and_spans
|
||||||
queue="export",
|
queue="export",
|
||||||
soft_time_limit=settings.BASEROW_JOB_SOFT_TIME_LIMIT,
|
soft_time_limit=settings.BASEROW_JOB_SOFT_TIME_LIMIT,
|
||||||
)
|
)
|
||||||
@local_cache.context()
|
|
||||||
def run_async_job(self, job_id: int):
|
def run_async_job(self, job_id: int):
|
||||||
"""Run the job task asynchronously"""
|
"""Run the job task asynchronously"""
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"type": "bug",
|
||||||
|
"message": "Clear local_cache for celery tasks",
|
||||||
|
"domain": "core",
|
||||||
|
"issue_number": 3528,
|
||||||
|
"bullet_points": [],
|
||||||
|
"created_at": "2025-03-26"
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue