Google Chat webhook sender and settings API (Feature 19) (#165)
CI / ci (push) Successful in 5m47s

Co-authored-by: orchestrator-agent <20+orchestrator-agent@code.cubecraftcreations.com>
This commit was merged in pull request #165.
This commit is contained in:
2026-10-09 14:35:32 -04:00
committed by approver_agent
parent d5ab945ee7
commit fc5b926edf
29 changed files with 1965 additions and 28 deletions
+2 -1
View File
@@ -12,7 +12,8 @@
// registered for their channel. A delivered row is marked sent. A failed
// delivery is retried after a backoff of one minute doubling up to one hour,
// until 24 hours after the row was created; the delivery that fails at or
// after that point marks it failed, with the error in last_error.
// after that point, or with an error wrapping ErrUndeliverable, marks it
// failed, with the error in last_error.
package notify
import (
+25
View File
@@ -422,6 +422,31 @@ func TestRetryThenSent(t *testing.T) {
}
}
func TestUndeliverableFailsAtOnce(t *testing.T) {
ctx := context.Background()
svc, st, _ := newTestService(t)
setPref(t, st, PlanReady, false, true)
sender := &fakeSender{fail: fmt.Errorf("%w: chat refused the message (status 400)", ErrUndeliverable)}
if err := svc.Register(ChannelChat, sender); err != nil {
t.Fatal(err)
}
const key = "plan_ready:2026-10-12"
if err := svc.Emit(ctx, planReady(key)); err != nil {
t.Fatal(err)
}
wait, err := svc.deliverDue(ctx)
if err != nil {
t.Fatal(err)
}
r := onlyRow(t, st, key, ChannelChat)
if r.Status != "failed" || r.Attempts != 1 || r.LastError.String != sender.fail.Error() {
t.Fatalf("row = %+v, want failed after one attempt with the sender's error", r)
}
if wait != -1 || len(sender.messages()) != 1 {
t.Fatalf("wait = %v after %d deliveries, want nothing pending after one", wait, len(sender.messages()))
}
}
func TestGiveUpAfter24Hours(t *testing.T) {
ctx := context.Background()
svc, st, c := newTestService(t)
+8 -2
View File
@@ -48,8 +48,14 @@ type Message struct {
Attempt int64
}
// ErrUndeliverable is wrapped by a Sender's error when retrying cannot
// help, such as a channel refusing the message outright: the worker marks
// the row failed at once instead of retrying it.
var ErrUndeliverable = errors.New("notify: undeliverable")
// Sender delivers notifications on one channel. Send returns nil once the
// channel has accepted m, and an error otherwise; the worker retries it.
// channel has accepted m, and an error otherwise; the worker retries it,
// unless the error wraps ErrUndeliverable.
// The error's text is stored in notification_outbox.last_error and logged,
// so it must never carry a secret: no webhook URL, key or token (a
// *url.Error quotes its URL).
@@ -235,7 +241,7 @@ func (s *Service) deliver(ctx context.Context, row db.NotificationOutbox) {
return
}
if !now.Before(deadline) {
if errors.Is(err, ErrUndeliverable) || !now.Before(deadline) {
logger.ErrorContext(ctx, "notification failed; giving up", "attempt", attempt, "error", err)
s.giveUp(ctx, logger, row, 1, err.Error())
return