feat(catalog): persist idempotent bulk operations and retryable deliveries
This commit is contained in:
1 parent
76e46d295c
commit
13665e0c3c
53 files changed
+1316
-76
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import type { EffectClaim } from "./model";
|
||||
export interface EffectRepository {
|
||||
claim(): Promise<EffectClaim | null>;
|
||||
complete(claim: EffectClaim): Promise<unknown>;
|
||||
fail(claim: EffectClaim): Promise<unknown>;
|
||||
}
|
||||
/** At-least-once delivery: handlers must tolerate replay after an expired claim. */
|
||||
export async function dispatchEffects(
|
||||
repo: EffectRepository,
|
||||
deliver: (claim: EffectClaim) => Promise<unknown>,
|
||||
) {
|
||||
for (let i = 0; i < 20; i++) {
|
||||
const claim = await repo.claim();
|
||||
if (!claim) return;
|
||||
try {
|
||||
await deliver(claim);
|
||||
} catch {
|
||||
await repo.fail(claim);
|
||||
continue;
|
||||
}
|
||||
await repo.complete(claim);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user