romele / git-trace public
62 commits · 1 branch · 1 tag · 1 contributor (top: Romele) · first commit 3d ago · last push 11m ago
src/webhook.h
#ifndef GT_WEBHOOK_H #define GT_WEBHOOK_H #include "db.h" #include "util.h" struct app_ctx; /* JSON string-content escaping (quotes are the caller's) */ void json_put_esc(struct buf *b, const char *s, size_t n); /* Queue one delivery per active hook of repo_id subscribed to `event`. * `payload` must be pre-encoded JSON. Returns rows queued, 0 if no * hook matches, -1 on DB error. */ int wh_enqueue(sqlite3 *db, long repo_id, const char *event, const char *payload); /* Detached background drain: double-fork + setsid + exec of * `git-trace webhook-run`. Async-signal-safe between the forks, so * it is callable from server threads and hooks alike; the parent * reaps the intermediate child immediately — no zombies. */ void wh_dispatch_async(struct app_ctx *c); /* Drain pending deliveries once (attempts < 5, cap 50 per run). * Returns the number of deliveries attempted, -1 on DB error. */ int wh_run(struct app_ctx *c); /* enqueue + kick the detached dispatcher when anything was queued — * the one-call convenience used by event sources */ void wh_notify(struct app_ctx *c, long repo_id, const char *event, const char *payload); #endif