From b33cad6d69aa65edddf53a45db918962d97fc39d Mon Sep 17 00:00:00 2001 From: Ben White Date: Wed, 2 Oct 2024 14:49:31 +0800 Subject: [PATCH] feat: Flush on celery posthog capture (#25308) --- posthog/tasks/plugin_server.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/posthog/tasks/plugin_server.py b/posthog/tasks/plugin_server.py index e4f588e93e8b6..11a6e0dd90355 100644 --- a/posthog/tasks/plugin_server.py +++ b/posthog/tasks/plugin_server.py @@ -1,6 +1,7 @@ from typing import Optional from celery import shared_task from django.conf import settings +import posthoganalytics from posthog.event_usage import report_team_action from posthog.tasks.email import send_hog_function_disabled, send_fatal_plugin_error @@ -42,5 +43,8 @@ def hog_function_state_transition(hog_function_id: str, state: int) -> None: }, ) + # TRICKY: It seems like without this call the events don't get flushed, possibly due to celery worker threads exiting... + posthoganalytics.flush() + if state >= 2: # 2 and 3 are disabled send_hog_function_disabled.delay(hog_function_id)