Skip to content

Commit

Permalink
fix: Added a bunch of logs to see whats up (#25365)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite authored Oct 3, 2024
1 parent fa152e8 commit 6faef7e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugin-server/src/utils/db/celery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class Celery {
const body = [args, kwargs, { callbacks: null, errbacks: null, chain: null, chord: null }]
/** A base64-encoded JSON representation of the body tuple. */
const bodySerialized = Buffer.from(JSON.stringify(body)).toString('base64')

await this.redisLPush(CELERY_DEFAULT_QUEUE, {
body: bodySerialized,
'content-encoding': 'utf-8',
Expand Down
10 changes: 10 additions & 0 deletions posthog/tasks/plugin_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
from celery import shared_task
from django.conf import settings
import posthoganalytics
from structlog import get_logger

from posthog.event_usage import report_team_action
from posthog.tasks.email import send_hog_function_disabled, send_fatal_plugin_error
from posthog.tasks.utils import CeleryQueue

logger = get_logger(__name__)

# IMPORTANT - Do not modify this without also modifying plugin-server/../celery.ts
# Same goes for this file path and the task names
queue = CeleryQueue.DEFAULT.value
Expand All @@ -28,9 +31,12 @@ def fatal_plugin_error(
def hog_function_state_transition(hog_function_id: str, state: int) -> None:
from posthog.models.hog_functions.hog_function import HogFunction

logger.info("hog_function_state_transition", hog_function_id=hog_function_id, state=state)

hog_function = HogFunction.objects.get(id=hog_function_id)

if not hog_function:
logger.warning("hog_function_state_transition: hog_function not found", hog_function_id=hog_function_id)
return

report_team_action(
Expand All @@ -44,7 +50,11 @@ 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...
logger.info("hog_function_state_transition: Flushing posthoganalytics")
posthoganalytics.flush()

if state >= 2: # 2 and 3 are disabled
logger.info("hog_function_state_transition: sending hog_function_disabled email")
send_hog_function_disabled.delay(hog_function_id)

logger.info("hog_function_state_transition: done")

0 comments on commit 6faef7e

Please sign in to comment.