DeleteExpiredWebhookEvents removes terminal rows whose expires_at has passed. Migration 026 sets a 30-day TTL on every event row; without this janitor the table grows monotonically and the (user_id, created_at) index degrades. Mirrors webhook.SubscriberStore.DeleteExpiredSubscriberDeliveries for the
(ctx context.Context)
| 146 | // fall out at day 30. That's the "page ops after many attempts" case |
| 147 | // recordFailure calls out — preferable to silent loss. |
| 148 | func (o *outbox) DeleteExpiredWebhookEvents(ctx context.Context) (int, error) { |
| 149 | tag, err := o.pool.Exec(ctx, |
| 150 | `DELETE FROM webhook_events |
| 151 | WHERE expires_at <= now() |
| 152 | AND status <> 'pending'`, |
| 153 | ) |
| 154 | if err != nil { |
| 155 | return 0, fmt.Errorf("delete expired webhook_events: %w", err) |
| 156 | } |
| 157 | return int(tag.RowsAffected()), nil |
| 158 | } |
| 159 | |
| 160 | func (o *outbox) PublishBestEffortTx(ctx context.Context, tx pgx.Tx, e Event) (wrote bool) { |
| 161 | if !o.flag.Enabled() { |