Skip to content

Commit

Permalink
fix(insights): prevent race condition (#26265)
Browse files Browse the repository at this point in the history
  • Loading branch information
EDsCODE authored Nov 20, 2024
1 parent d836bc8 commit 386382b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions posthog/clickhouse/client/async_task_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import typing
from contextlib import contextmanager
from functools import partial
import uuid

from celery import chain
from celery.canvas import Signature
Expand All @@ -22,12 +23,15 @@ def kick_off_task(
query_status: QueryStatus,
task_signature: Signature,
) -> None:
task = task_signature.apply_async()
task_id = str(uuid.uuid4())
query_status.task_id = task_id
manager.store_query_status(query_status)
task = task_signature.apply_async(task_id=task_id)

# During end-to-end tests, the task is executed synchronously, so we have to refresh the status.
if isinstance(task, EagerResult):
query_status = manager.get_query_status()
query_status.task_id = task.id
manager.store_query_status(query_status)
manager.store_query_status(query_status)


def get_task_chain() -> list[tuple[Signature, "QueryStatusManager", QueryStatus]]:
Expand Down

0 comments on commit 386382b

Please sign in to comment.