Repository navigation
feat(webhooks): booking.reminder event fired with each reminder (#259) - #279
dominik-myszkowski wants to merge 1 commit into
Conversation
Fires from the reminder.send job at each configured hours_before, after the same gates as the reminder email (booking confirmed, host notify_reminder on), and carries hours_before in data regardless of the webhook's field selection. Enqueued before the email via EnqueueOnce: the delivery ID is derived from (webhook, booking, hours_before, start_at) and inserted with INSERT OR IGNORE, so a job retried after a failed email does not deliver twice, while a reschedule gets its own event. No schema change. Refs Calnode#259
There was a problem hiding this comment.
ℹ️ No critical issues — one upgrade-window edge case inline.
Approach: sound — the event is raised from the existing reminder.send job and deduped with a deterministic delivery ID, so there is no schema change and no second scheduling path to keep in sync.
Reviewed changes
- New event wired through:
booking.reminderadded to the handler allowlist and the admin webhooks page, so it is subscribable through both the API and the UI. hours_beforein the payload: a non-selectableBookingPayloadfield appended bybuildDatawhenever set, so reminder events carry it even when the webhook narrowed its field selection.EnqueueOnce: deterministic UUID-shaped delivery ID from (webhook, key) inserted withINSERT OR IGNORE, skipping thewebhook.deliverjob on conflict;Enqueueis untouched for the other events.- Worker gate + key:
sendReminderpasseshours_beforethrough and enqueues the event before the email, gated onconfirmed/notify_reminder, with a key of (booking,hours_before,start_at). - Coverage and docs: webhook, worker and handler tests plus the ARCHITECTURE §13 rewrite.
deepseek-v4.1-flash | 𝕏
| Status: status, | ||
| LocationValue: d.LocationValue, | ||
| CreatedAt: created, | ||
| HoursBefore: hoursBefore, |
There was a problem hiding this comment.
Reminder jobs queued by an older version carry only booking_id, so hoursBefore is 0 here and buildData drops hours_before — the event then arrives without the field this PR promises it always carries (the repo still treats that old-format job as a live state in TestRescheduleBooking_updatesReminderJob). The receiver cannot tell a 24h reminder from a 2h one for those in-flight jobs. Consider treating a non-positive hours_before as unidentifiable: skip the webhook (with a log line) or derive it from the event type's configured reminders, rather than emitting an event without it.
Technical details
# Legacy reminder jobs deliver booking.reminder without hours_before
## Affected sites
- `internal/worker/worker.go:403` — `HoursBefore: hoursBefore` forwards the job payload value verbatim; it is 0 for jobs queued before the field existed.
- `internal/webhook/webhook.go:381` — `if bd.core.HoursBefore > 0` omits the key, so the delivered `data` has no `hours_before`.
- `internal/handler/booking_handler.go:2176` and `:2267` — current writers do include it; only pre-existing pending rows are affected.
- `internal/handler/reschedule_test.go:94` — the suite still seeds an "old-format reminder job (no hours_before field)", confirming that shape is considered reachable.
## Required outcome
- A `booking.reminder` delivery always carries `hours_before`, or the worker does not raise the event when it cannot determine which reminder fired (and logs the skip).
## Suggested approach (optional)
- Guard the `enqueueReminderWebhook` call on `p.HoursBefore > 0`, or look the value up from `event_type_reminders` for the booking's event type when it is zero.
## Open questions for the human
- Is upgrading across the version that introduced `hours_before` in the `reminder.send` payload a supported path with in-flight jobs? If not, a comment recording that constraint is enough.
Implements option B from #259: a
booking.reminderwebhook event, so an external SMS/push sender can stay stateless while Calnode keeps owning scheduling, reschedules and cancellations.What it does
booking.reminderis a new subscribable event (backend allowlist and the event list on the webhooks page). It fires from the existingreminder.sendjob, once per configuredhours_before, with the usual booking payload.Your three conditions
hours_beforein the payload. It is part of the event rather than a selectable booking field, sobooking.reminderalways carries it indatawhatever the webhook's field selection, and no other event does.confirmedand the host'snotify_reminderis on. If reminder emails are off, no event is sent.webhook.Service.EnqueueOnce(ctx, event, payload, key). The delivery ID is derived from (webhook ID, key) as a UUID-shaped SHA-256 value, and is inserted withINSERT OR IGNORE. A second call with the same key creates neither a delivery nor awebhook.deliverjob, even after the first delivery has finished, which is where the jobs table's live-row(type, payload)guard no longer helps. The key is (booking,hours_before,start_at): a retried job collapses, while a reschedule gets its own event for the new time.Enqueueitself is unchanged for every other event. A side benefit is thatX-Calnode-Deliveryis stable, so receivers can dedupe on it too.ARCHITECTURE §13 no longer says the event deliberately does not exist, and describes the above instead.
Tests
webhook:hours_beforeis sent even when the webhook selected onlyid, and is absent onbooking.created.worker:notify_reminder = 0or for a cancelled booking;webhook.deliverjob;hours_before, a duplicate job for the same time, and a reschedule give exactly three deliveries.handler: a webhook subscribing tobooking.reminderis accepted.Mutation check: with a random instead of a deterministic key, the two dedup tests fail.
gofmt,go vet ./...,go build ./...,go test ./...,go run ./cmd/i18n-coverageandsvelte-checkpass locally.I also checked it on a running binary, merged locally with #278 to reach a loopback receiver (the two merge cleanly). The setup was a booking two days out with reminders
[72, 24]."hours_before": 72, and the 24h one stayed pending.start_atand a different delivery ID.