Make Square webhook dedup restart-safe via database

The in-memory dedup is now only a fast path; the square_webhook_events INSERT ... ON CONFLICT DO NOTHING is the source of truth, so replays across restarts and after FIFO eviction are skipped. A DB failure fails closed with 503 so Square retries. Empty event_ids are rejected with 400 (no dispatch, no dedup row). Ordering trade-off (insert-before-dispatch) documented for when handlers mutate state.
This commit is contained in:
2026-08-22 00:34:49 +01:00
parent c9d55817f6
commit 5ea89da2ad
3 changed files with 311 additions and 16 deletions
@@ -0,0 +1,20 @@
//go:build test
package webhooks
import (
"os"
"testing"
"crussell/db"
"crussell/testutils/testdb"
)
func TestMain(m *testing.M) {
pool := testdb.CreateTestDatabase("crussell_test_handlers_webhooks")
db.Conn = db.NewPoolProxy(pool)
testdb.SeedBaseline(pool)
code := m.Run()
testdb.DestroyTestDatabase(pool, "crussell_test_handlers_webhooks")
os.Exit(code)
}