Skip to content

Retention and pruning

Knocker keeps retention intentionally small:

  • explicit prune primitives remain the source of truth
  • automation runs through Honker scheduling/queue primitives
  • each automated run calls the shared core retention-pass primitive
  • no richer policy engine
  • no calendar or cron semantics
summary = webhooks.prune_events(
statuses=["handled", "ignored"],
older_than=1700000000,
limit=100,
)
orphans = webhooks.prune_orphan_deliveries(
older_than=1700000000,
limit=100,
)
audits = webhooks.list_prune_audits(kind="prune_events", limit=50)
policy = knocker.RetentionPolicy(
interval_s=60,
event_older_than_s=7 * 24 * 60 * 60,
orphan_deliveries_older_than_s=24 * 60 * 60,
)
await webhooks.run_retention(policy, stop_event=stop)

Bindings expose retention helpers over the same core retention-pass primitive. The policy shape is:

  • interval
  • event statuses
  • event age cutoff
  • event prune limit
  • orphan-delivery age cutoff
  • orphan-delivery prune limit

Important boundaries:

  • automation is intentionally small
  • recurrence comes from Honker Scheduler
  • each maintenance job calls the shared core retention-pass primitive
  • automated runs write the same durable audit rows as manual runs
  • multiple processes can run retention workers against the same SQLite file without duplicate prune runs

Configuration is simpler than runtime:

  • multiple runners are acceptable
  • one process/instance should still be treated as the source of truth for retention configuration for a given database

older_than is strict: rows qualify only when received_at < older_than.

Candidate selection is:

  • oldest-first
  • bounded by explicit limit
  • all-or-nothing inside one transaction per prune call

Returned counts:

  • events_pruned
  • attempts_pruned
  • deliveries_pruned
  • live_jobs_pruned

This is about the orphan axis only: event_id IS NULL. It is not a generic “invalid deliveries” delete switch.

knocker_deliveries is append-only during normal ingest and operator inspection. Explicit pruning is the documented retention exception that may delete old delivery rows.

Every successful prune call records an audit row in the same transaction. Each PruneAudit includes:

  • kind: 'prune_events' or 'prune_orphan_deliveries'
  • queue_name: the Honker queue pruned against
  • executed_at: unixepoch timestamp
  • events_pruned, deliveries_pruned, attempts_pruned, live_jobs_pruned
  • summary_json: operator inputs (statuses, older_than, limit)

No-op prunes (zero rows deleted) still write an audit row with zero counts. Audit rows are never targeted by ordinary prune operations.

Still intentionally out of scope:

  • pruning failed or dead events
  • dry-run mode
  • endpoint-specific retention policy
  • local-day or DST-aware retention semantics