Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(hogbox-preview): run a celery worker so queued tasks run (#113610)

Frank Hamandc898977025e6
diff --git a/tools/hogbox-preview/README.md b/tools/hogbox-preview/README.md
index 7969909f5414..a1a4f9920227 100644
--- a/tools/hogbox-preview/README.md
+++ b/tools/hogbox-preview/README.md
@@ -50,6 +50,7 @@ print(url) # https://pen-….boxes.hogland.prod-us.posthog.dev/ (stable across
5. **Sync HogFunction templates** - start the CDP service and load destination
templates into the restored database before the preview becomes available.
6. **Sync feature flags** - run `sync_feature_flags` so each flag in the PR's `constants.tsx` that the golden lacks exists and is on.
+ A celery `worker` runs in the preview, without the scheduler, so tasks such as the flag cache refresh that a flag save queues actually run.
7. **Serve + report** — the box is HTTP-exposed; the URL is posted to the PR.
A Caddy container (`static-proxy`) takes the exposed port.
It serves `/static/*` from `staticfiles/` and sends all other requests to web, so asset requests do not use Django threads.
diff --git a/tools/hogbox-preview/hogbox_preview/stack.py b/tools/hogbox-preview/hogbox_preview/stack.py
index 9dd7f35c027a..e27762c7ec37 100644
--- a/tools/hogbox-preview/hogbox_preview/stack.py
+++ b/tools/hogbox-preview/hogbox_preview/stack.py
@@ -214,6 +214,8 @@ class PostHogPreviewStack:
COMPOSE_PROJECT = "posthog"
SELF_CAPTURE_SERVICES = ["capture", "feature-flags", "property-defs-rs", "ingestion-general"]
TELEMETRY_SERVICES = ["capture-logs", "ingestion-logs", "ingestion-traces", "ingestion-metrics", "otel-collector"]
+ CELERY_SERVICES = ["worker"]
+ CELERY_CONCURRENCY = 2
REPO_DIR = "/home/hog/posthog"
COMPOSE = "docker-compose.dev-full.yml"
OVERRIDE = "docker-compose.preview.yml"
@@ -573,7 +575,7 @@ class PostHogPreviewStack:
" - PERSONHOG_ENABLED=true",
*_OTEL_ENV,
]
- lines += self._self_capture_services() + self._telemetry_services()
+ lines += self._self_capture_services() + self._telemetry_services() + self._celery_worker_service()
# Mirror the bake script's personhog service definitions (hogland
# scripts/posthog-preview-setup.sh): dev-full.yml carries NO personhog
# services (dev runs them via hogli), so define them here the way HOBBY
@@ -701,6 +703,30 @@ class PostHogPreviewStack:
]
self.backend.write_file(f"{self.repo_dir}/{self.OVERRIDE}", "\n".join(lines) + "\n")
+ def _celery_worker_service(self) -> list[str]:
+ lines = [" worker:"]
+ if self.image:
+ lines.append(f" image: {self.image}")
+ lines.append(" command: ./bin/docker-worker-celery")
+ if self.image and self.mount:
+ lines.append(" volumes:")
+ lines += [f" - ./{src}:{dst}" for src, dst in self.MOUNTS]
+ return [
+ *lines,
+ " environment:",
+ f" - SITE_URL={self.backend.web_url}",
+ " - DEBUG=0",
+ f" - SECRET_KEY={self.secret_key}",
+ f" - OIDC_RSA_PRIVATE_KEY={self.oidc_private_key}",
+ " - PERSONHOG_ADDR=personhog-router:50052",
+ " - USE_LOCAL_SETUP=1",
+ " - SELF_CAPTURE=1",
+ " - SELF_CAPTURE_HOST=http://static-proxy:8000",
+ f" - WEB_CONCURRENCY={self.CELERY_CONCURRENCY}",
+ " - OTEL_SERVICE_NAME=posthog-celery-worker",
+ *_OTEL_ENV,
+ ]
+
def _self_capture_services(self) -> list[str]:
return [
" ingestion-general:",
@@ -862,7 +888,14 @@ class PostHogPreviewStack:
timing.stage("start web + temporal worker containers")
self.write_otel_collector_config()
services = " ".join(
- ["web", "temporal-django-worker", "static-proxy", *self.SELF_CAPTURE_SERVICES, *self.TELEMETRY_SERVICES]
+ [
+ "web",
+ "temporal-django-worker",
+ "static-proxy",
+ *self.CELERY_SERVICES,
+ *self.SELF_CAPTURE_SERVICES,
+ *self.TELEMETRY_SERVICES,
+ ]
)
self.backend.run_long(self._compose(f"up -d --no-build {services}"), name="up-web", timeout=1800)
@@ -1008,7 +1041,7 @@ class PostHogPreviewStack:
self.backend.wait_http_ok("/_health", expect=200, timeout=900)
def report_pipeline_health(self, settle_seconds: int = 90) -> None:
- services = " ".join([*self.SELF_CAPTURE_SERVICES, *self.TELEMETRY_SERVICES])
+ services = " ".join([*self.CELERY_SERVICES, *self.SELF_CAPTURE_SERVICES, *self.TELEMETRY_SERVICES])
compose = f"docker compose -f {self.COMPOSE} -f {self.OVERRIDE}"
report = "/tmp/hogbox-pipeline-health.txt"
script = (
diff --git a/tools/hogbox-preview/tests/test_deep_health.py b/tools/hogbox-preview/tests/test_deep_health.py
index e52151b2eac0..7705b4a4a451 100644
--- a/tools/hogbox-preview/tests/test_deep_health.py
+++ b/tools/hogbox-preview/tests/test_deep_health.py
@@ -141,7 +141,7 @@ class OverrideTemporalParityTest(unittest.TestCase):
stack = PostHogPreviewStack(backend)
stack.write_override()
override = backend.files[f"{stack.repo_dir}/{stack.OVERRIDE}"]
- self.assertEqual(override.count(f"SECRET_KEY={stack.secret_key}"), 2)
+ self.assertEqual(override.count(f"SECRET_KEY={stack.secret_key}"), 3)
def test_worker_pins_the_image(self):
# dev-full's worker carries `build: .` — an unpinned image turns
@@ -163,7 +163,7 @@ class OverrideTemporalParityTest(unittest.TestCase):
def test_both_services_force_the_local_warehouse_path(self):
# A preview runs DEBUG=0, so USE_LOCAL_SETUP has to be forced or every
# warehouse path reaches for real AWS creds instead of the stack's MinIO.
- self.assertEqual(self._override().count("USE_LOCAL_SETUP=1"), 2)
+ self.assertEqual(self._override().count("USE_LOCAL_SETUP=1"), 3)
def test_temporal_server_started_with_deps_but_not_the_worker(self):
# The server must be listening before web schedules; the worker imports