feat(events): run notify side effects and ack on one fenced transaction

Shadow dry-runs the same handler then rolls back, writing only the intended digest.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
weichen
2026-09-15 09:26:36 +00:00
co-authored by Cursor
parent 6702b16249
commit 16a31f8aa5
7 changed files with 263 additions and 43 deletions
+7
View File
@@ -11,9 +11,12 @@ import (
"syscall"
"time"
"chat-agent-system/internal/app/docnotify"
"chat-agent-system/internal/config"
"chat-agent-system/internal/db"
"chat-agent-system/internal/docgov"
"chat-agent-system/internal/events"
"chat-agent-system/internal/notification"
"github.com/jackc/pgx/v5/pgxpool"
)
@@ -57,6 +60,10 @@ func main() {
owner := fmt.Sprintf("events-%d", os.Getpid())
disp := events.NewDispatcher(pool, cfg.Env, owner)
notify := notification.NewService(pool)
_ = disp.Register(events.ConsumerNotify, (&docnotify.EventConsumer{
Notify: notify, Docs: docgov.NewGovernanceEngine(pool), Env: cfg.Env,
}).HandleLease)
mux := http.NewServeMux()
mux.HandleFunc("GET /health", func(w http.ResponseWriter, _ *http.Request) {
writeJSON(w, http.StatusOK, map[string]any{"status": "ok", "env": cfg.Env, "owner": owner})