mirror of
https://github.com/hanzoai/insights.git
synced 2026-10-30 16:15:31 +00:00
The tree was a debranded snapshot of upstream taken around 2026-02-20, and upstream has moved about five months since. This replaces it with upstream master, mechanically re-derived: bin/debrand does the rename, and the pipeline and squashed migrations are restored from the shipped tree. Not a merge. The previous import replaced the tree wholesale in a single commit, so there is no shared content history to merge against. Reproducing the rename on the new tree is what actually converges. What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints, compose files, LLM.md, and insights/migrations. The squashed initial migration is load-bearing — the live database records it by name, so upstream's ~918 individual migrations cannot come back. Nine products are dropped as unreferenced. Twenty-one more that we do not run are kept anyway because the core app still imports them; unpicking those is a refactor and does not belong in a rebase. This base does not build yet, and the reasons are not in the rename: upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against our 4.2, and the dependency manifests still name upstream packages that we republish under our own names. Those are decisions, not renames.
57 lines
2.3 KiB
Python
57 lines
2.3 KiB
Python
"""Reconciliation sweep for loop trigger schedules. See products/tasks/docs/LOOPS.md
|
|
(Lifecycle and reconciliation).
|
|
|
|
Schedule sync to Temporal is best-effort: `sync_loop_trigger_schedule` records `pending` or
|
|
`failed` on the trigger instead of raising, so a transient Temporal outage during a create or
|
|
edit leaves a schedule trigger whose Temporal Schedule was never created or updated. This sweep
|
|
re-drives those rows so a trigger never strands unsynced.
|
|
"""
|
|
|
|
import structlog
|
|
from celery import shared_task
|
|
|
|
from insights.scoping_audit import skip_team_scope_audit
|
|
|
|
from products.tasks.backend.loop_service import sync_loop_trigger_schedule
|
|
from products.tasks.backend.models import LoopTrigger
|
|
|
|
logger = structlog.get_logger(__name__)
|
|
|
|
_UNSYNCED_STATUSES = (LoopTrigger.ScheduleSyncStatus.PENDING, LoopTrigger.ScheduleSyncStatus.FAILED)
|
|
# After a Temporal outage the whole cross-team backlog goes unsynced at once; each re-sync is a
|
|
# Temporal round trip and the Celery task has a 110s soft limit, so cap the batch per sweep and
|
|
# let the 10-minute cadence drain the rest.
|
|
_RECONCILE_BATCH_SIZE = 200
|
|
|
|
|
|
def reconcile_loop_trigger_schedules() -> int:
|
|
"""Re-sync schedule triggers stuck in `pending`/`failed`, oldest first, capped per sweep.
|
|
Returns the count re-synced.
|
|
|
|
Cross-team janitor sweep, mirroring `sweep_loop_task_retention`. `sync_loop_trigger_schedule`
|
|
is idempotent and swallows Temporal errors (re-recording `failed`), so a still-down Temporal
|
|
just leaves the row for the next sweep rather than raising.
|
|
"""
|
|
triggers = list(
|
|
LoopTrigger.objects.unscoped()
|
|
.filter(
|
|
type=LoopTrigger.TriggerType.SCHEDULE,
|
|
schedule_sync_status__in=_UNSYNCED_STATUSES,
|
|
completed_at__isnull=True,
|
|
# A soft-deleted loop's schedule was torn down on delete; never recreate it here.
|
|
loop__deleted=False,
|
|
)
|
|
.select_related("loop")
|
|
.order_by("updated_at")[:_RECONCILE_BATCH_SIZE]
|
|
)
|
|
for trigger in triggers:
|
|
sync_loop_trigger_schedule(trigger)
|
|
return len(triggers)
|
|
|
|
|
|
@shared_task(ignore_result=True, soft_time_limit=110, time_limit=170)
|
|
@skip_team_scope_audit
|
|
def reconcile_loop_trigger_schedules_task() -> None:
|
|
reconciled_count = reconcile_loop_trigger_schedules()
|
|
logger.info("loop_reconciliation.swept", reconciled_count=reconciled_count)
|