mirror of
https://github.com/hanzoai/insights.git
synced 2026-10-30 16:15:31 +00:00
drop_closure exists to refuse a drop that is really a refactor: if code we keep still imports a product, deleting it is a ModuleNotFoundError waiting for the next boot. It only ever read Python, so half the dependency graph was invisible to it and five products whose TypeScript the core still imports were dropped anyway — 21 files left importing 25 specifiers that resolve to nothing, including lib/api.ts, which 760 files import, and seven lazy scene imports in productScenes.tsx. Django booted past it and the bundle did not, which is why the Python-only rule looked like it was working. The closure now reads both module systems through one table of (extensions, pattern) pairs, so a third one is a row rather than a branch. The TypeScript pattern is anchored on the import keyword rather than on the path, because jest's testPathIgnorePatterns and oxlint's ignore list quote a product path precisely because it is NOT built; matching those would hold desktop, the 4,797-file product the drop is mostly for. integrations, wizard, platform_features, visual_review and ai_gateway come back with their Django apps and workspace entries, since the closure now spares them. desktop, field_notes, ingestion and support stay dropped.
78 lines
2.5 KiB
Python
78 lines
2.5 KiB
Python
import logging
|
|
from typing import Any
|
|
|
|
from celery import shared_task
|
|
from celery.app.task import Task
|
|
|
|
from insights.celery_queues import CeleryQueue
|
|
|
|
from products.event_definitions.backend.logic.placeholder import (
|
|
PlaceholderEventDefinition,
|
|
create_placeholder_event_definitions,
|
|
)
|
|
from products.wizard.backend.facade.enums import RunPhase
|
|
from products.wizard.backend.models import WizardSession
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
MAX_PLANNED_EVENT_DEFINITIONS = 50
|
|
MAX_PLANNED_EVENT_CANDIDATES = 500
|
|
MAX_EVENT_NAME_LENGTH = 400
|
|
|
|
|
|
def _planned_event_definitions(event_plan: dict[str, Any] | None) -> list[PlaceholderEventDefinition]:
|
|
events = event_plan.get("events") if isinstance(event_plan, dict) else None
|
|
if not isinstance(events, list):
|
|
return []
|
|
|
|
definitions: list[PlaceholderEventDefinition] = []
|
|
seen_names: set[str] = set()
|
|
for planned_event in events[:MAX_PLANNED_EVENT_CANDIDATES]:
|
|
if not isinstance(planned_event, dict):
|
|
continue
|
|
|
|
raw_name = planned_event.get("name")
|
|
if not isinstance(raw_name, str):
|
|
continue
|
|
name = raw_name.strip().replace("\x00", "\ufffd")
|
|
if not name or name.startswith("$") or len(name) > MAX_EVENT_NAME_LENGTH or name in seen_names:
|
|
continue
|
|
|
|
description = planned_event.get("description")
|
|
definitions.append(
|
|
PlaceholderEventDefinition(
|
|
name=name,
|
|
description=description.replace("\x00", "\ufffd") if isinstance(description, str) else None,
|
|
)
|
|
)
|
|
seen_names.add(name)
|
|
if len(definitions) == MAX_PLANNED_EVENT_DEFINITIONS:
|
|
break
|
|
|
|
return definitions
|
|
|
|
|
|
@shared_task(
|
|
bind=True,
|
|
ignore_result=True,
|
|
max_retries=5,
|
|
queue=CeleryQueue.DEFAULT.value,
|
|
)
|
|
def sync_wizard_event_definitions(self: Task, team_id: int, session_id: str) -> None:
|
|
try:
|
|
session = WizardSession.objects.for_team(team_id).filter(session_id=session_id).first()
|
|
if session is None or session.run_phase != RunPhase.COMPLETED.value:
|
|
return
|
|
|
|
create_placeholder_event_definitions(
|
|
team_id=team_id,
|
|
definitions=_planned_event_definitions(session.event_plan),
|
|
)
|
|
except Exception as error:
|
|
countdown = min(2**self.request.retries, 60)
|
|
logger.warning(
|
|
"Retrying wizard event definition sync",
|
|
extra={"team_id": team_id, "session_id": session_id, "retry": self.request.retries},
|
|
)
|
|
raise self.retry(exc=error, countdown=countdown)
|