@burdenoff/be-sdk 2026.1130.1 → 2026.1130.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{EventQueueFactory-BhNJE93c.js → EventQueueFactory-S_K9dVRM.js} +32 -3
- package/dist/EventQueueFactory-S_K9dVRM.js.map +1 -0
- package/dist/auth/index.d.ts +1 -1
- package/dist/{RedisStreamsConnection-CY8WySJy.js → backoff-BIk9Wy8O.js} +19 -2
- package/dist/backoff-BIk9Wy8O.js.map +1 -0
- package/dist/consumer-health-CaKEsnsv.js +33 -0
- package/dist/consumer-health-CaKEsnsv.js.map +1 -0
- package/dist/event-queue/index.d.ts +2 -2
- package/dist/event-queue/index.js +6 -5
- package/dist/{event-queue-CKvgAqF3.js → event-queue-C58O9KEG.js} +332 -15
- package/dist/event-queue-C58O9KEG.js.map +1 -0
- package/dist/feature-flags/index.d.ts +1 -1
- package/dist/graph/index.d.ts +1 -1
- package/dist/graph/index.js +2 -2
- package/dist/{graph-BdoM7_90.js → graph-LKv5fzet.js} +4 -4
- package/dist/{graph-BdoM7_90.js.map → graph-LKv5fzet.js.map} +1 -1
- package/dist/{graph-emitter-DpaWxRBp.js → graph-emitter-D_zQC0MZ.js} +2 -2
- package/dist/{graph-emitter-DpaWxRBp.js.map → graph-emitter-D_zQC0MZ.js.map} +1 -1
- package/dist/graphql/index.js +1 -1
- package/dist/{graphql-DzzWneMu.js → graphql-Gusog8jG.js} +3 -5
- package/dist/graphql-Gusog8jG.js.map +1 -0
- package/dist/{index-CjY5YV9F.d.ts → index-BMy-d2_f.d.ts} +1 -1
- package/dist/{index-BaB4Nsv7.d.ts → index-C4hRRihw.d.ts} +1 -1
- package/dist/{index-CGPNFIR3.d.ts → index-CeaJcbar.d.ts} +67 -2
- package/dist/{index-BFNCCa2W.d.ts → index-Cl3Xiw1O.d.ts} +2 -2
- package/dist/{index-DYKWUbL4.d.ts → index-GzZunmGS.d.ts} +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +6 -6
- package/dist/init/index.js +1 -1
- package/dist/{init-DaHOxzwF.js → init-2gMeersr.js} +2 -2
- package/dist/{init-DaHOxzwF.js.map → init-2gMeersr.js.map} +1 -1
- package/dist/{middleware-z8KzMFU_.js → middleware-Cd1Z4_DD.js} +2 -2
- package/dist/{middleware-z8KzMFU_.js.map → middleware-Cd1Z4_DD.js.map} +1 -1
- package/dist/prisma/index.js +2 -2
- package/dist/{prisma-CUij0pph.js → prisma-Bo-C0XUv.js} +3 -3
- package/dist/{prisma-CUij0pph.js.map → prisma-Bo-C0XUv.js.map} +1 -1
- package/dist/server/index.d.ts +3 -3
- package/dist/server/index.js +302 -10
- package/dist/server/index.js.map +1 -1
- package/dist/{types-2PuLMwAy.d.ts → types-C36JkwDg.d.ts} +85 -2
- package/package.json +1 -1
- package/dist/EventQueueFactory-BhNJE93c.js.map +0 -1
- package/dist/RedisStreamsConnection-CY8WySJy.js.map +0 -1
- package/dist/event-queue-CKvgAqF3.js.map +0 -1
- package/dist/graphql-DzzWneMu.js.map +0 -1
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-ad2WFvuA.js";
|
|
2
|
-
import { a as RedisStreamsEventConsumer, l as QueueType, r as RedisStreamsEventPublisher, t as EventQueueFactory } from "./EventQueueFactory-
|
|
3
|
-
import {
|
|
4
|
-
import { a as MemoryEventBus, c as MemoryEventQueue, d as createMemoryPublisher, i as resetGraphEventEmitter, l as createGraphEventEmitter$1, n as createGraphEventEmitter, o as MemoryEventConsumer, r as getGraphEventEmitter, s as MemoryEventPublisher, t as GraphEventEmitterImpl, u as createMemoryConsumer } from "./graph-emitter-
|
|
2
|
+
import { a as RedisStreamsEventConsumer, l as QueueType, r as RedisStreamsEventPublisher, t as EventQueueFactory } from "./EventQueueFactory-S_K9dVRM.js";
|
|
3
|
+
import { f as streamKey, l as matchSubject, n as RedisStreamsConnection, s as dlqKey, t as computeBackoffMs } from "./backoff-BIk9Wy8O.js";
|
|
4
|
+
import { a as MemoryEventBus, c as MemoryEventQueue, d as createMemoryPublisher, i as resetGraphEventEmitter, l as createGraphEventEmitter$1, n as createGraphEventEmitter, o as MemoryEventConsumer, r as getGraphEventEmitter, s as MemoryEventPublisher, t as GraphEventEmitterImpl, u as createMemoryConsumer } from "./graph-emitter-D_zQC0MZ.js";
|
|
5
5
|
import { a as logger } from "./logger-B6rCpb7D.js";
|
|
6
6
|
import { a as resolveEventStreamsUrl, c as resolveGraphEventsUrlSource, i as eventKeyScopeForUrl, n as GRAPH_EVENTS_URL_ENV_KEYS, o as resolveEventStreamsUrlSource, s as resolveGraphEventsUrl, t as EVENT_STREAMS_URL_ENV_KEYS } from "./env-DdaoGjIt.js";
|
|
7
|
+
import { n as registerConsumerHealthSource, t as getConsumerHealth } from "./consumer-health-CaKEsnsv.js";
|
|
8
|
+
import { l as getMetricsRegistry } from "./metrics-collector-DXQrMUle.js";
|
|
9
|
+
import { a as unregisterDisposable, i as registerDisposable } from "./lifecycle-DeoLSX0U.js";
|
|
7
10
|
import { randomUUID } from "node:crypto";
|
|
8
11
|
|
|
9
12
|
// src/event-queue/module-events.ts
|
|
@@ -739,7 +742,7 @@ const REFERENCE_PRODUCT_EVENT_TAXONOMY = defineEventTaxonomy({
|
|
|
739
742
|
* them, so each handler would silently miss part of its traffic.
|
|
740
743
|
*/
|
|
741
744
|
const SERVICE_NAME$1 = /^[a-z][a-z0-9-]*[a-z0-9]$/;
|
|
742
|
-
function errorMessage$
|
|
745
|
+
function errorMessage$2(error) {
|
|
743
746
|
return error instanceof Error ? error.message : String(error);
|
|
744
747
|
}
|
|
745
748
|
function encodePayload(payload) {
|
|
@@ -752,13 +755,13 @@ function toMessage(event) {
|
|
|
752
755
|
payload: event.data,
|
|
753
756
|
event,
|
|
754
757
|
ack() {
|
|
755
|
-
event.ack().catch((err) => logger.warn("[Events] ack failed", { error: errorMessage$
|
|
758
|
+
event.ack().catch((err) => logger.warn("[Events] ack failed", { error: errorMessage$2(err) }));
|
|
756
759
|
},
|
|
757
760
|
nak(delay) {
|
|
758
|
-
event.nak(delay).catch((err) => logger.warn("[Events] nak failed", { error: errorMessage$
|
|
761
|
+
event.nak(delay).catch((err) => logger.warn("[Events] nak failed", { error: errorMessage$2(err) }));
|
|
759
762
|
},
|
|
760
763
|
term() {
|
|
761
|
-
event.term().catch((err) => logger.warn("[Events] term failed", { error: errorMessage$
|
|
764
|
+
event.term().catch((err) => logger.warn("[Events] term failed", { error: errorMessage$2(err) }));
|
|
762
765
|
}
|
|
763
766
|
};
|
|
764
767
|
}
|
|
@@ -831,7 +834,7 @@ var EventsManager = class {
|
|
|
831
834
|
...stream ? { options: { stream } } : {}
|
|
832
835
|
});
|
|
833
836
|
} catch (error) {
|
|
834
|
-
logger.error(`[Events] Failed to publish to ${subject}`, { error: errorMessage$
|
|
837
|
+
logger.error(`[Events] Failed to publish to ${subject}`, { error: errorMessage$2(error) });
|
|
835
838
|
throw error;
|
|
836
839
|
}
|
|
837
840
|
}
|
|
@@ -870,7 +873,7 @@ var EventsManager = class {
|
|
|
870
873
|
} catch (error) {
|
|
871
874
|
logger.error("[Events] Handler error", {
|
|
872
875
|
subject: event.subject,
|
|
873
|
-
error: errorMessage$
|
|
876
|
+
error: errorMessage$2(error)
|
|
874
877
|
});
|
|
875
878
|
await event.nak();
|
|
876
879
|
}
|
|
@@ -899,7 +902,7 @@ var EventsManager = class {
|
|
|
899
902
|
} catch (error) {
|
|
900
903
|
logger.warn("[Events] unsubscribe failed", {
|
|
901
904
|
subject,
|
|
902
|
-
error: errorMessage$
|
|
905
|
+
error: errorMessage$2(error)
|
|
903
906
|
});
|
|
904
907
|
}
|
|
905
908
|
};
|
|
@@ -914,14 +917,14 @@ var EventsManager = class {
|
|
|
914
917
|
try {
|
|
915
918
|
await subscription.unsubscribe();
|
|
916
919
|
} catch (error) {
|
|
917
|
-
logger.warn("[Events] unsubscribe failed", { error: errorMessage$
|
|
920
|
+
logger.warn("[Events] unsubscribe failed", { error: errorMessage$2(error) });
|
|
918
921
|
}
|
|
919
922
|
}));
|
|
920
923
|
this.active.clear();
|
|
921
924
|
for (const consumer of this.consumers.values()) try {
|
|
922
925
|
await consumer.disconnect();
|
|
923
926
|
} catch (error) {
|
|
924
|
-
logger.warn("[Events] consumer disconnect failed", { error: errorMessage$
|
|
927
|
+
logger.warn("[Events] consumer disconnect failed", { error: errorMessage$2(error) });
|
|
925
928
|
}
|
|
926
929
|
this.consumers.clear();
|
|
927
930
|
if (this.publisherConnecting) await this.publisherConnecting.catch(() => void 0);
|
|
@@ -929,7 +932,7 @@ var EventsManager = class {
|
|
|
929
932
|
try {
|
|
930
933
|
await this.publisher.disconnect();
|
|
931
934
|
} catch (error) {
|
|
932
|
-
logger.warn("[Events] publisher disconnect failed", { error: errorMessage$
|
|
935
|
+
logger.warn("[Events] publisher disconnect failed", { error: errorMessage$2(error) });
|
|
933
936
|
}
|
|
934
937
|
this.publisher = null;
|
|
935
938
|
}
|
|
@@ -976,6 +979,311 @@ function createEventsManagerSingleton(options) {
|
|
|
976
979
|
};
|
|
977
980
|
}
|
|
978
981
|
|
|
982
|
+
// src/event-queue/start-supervisor.ts
|
|
983
|
+
/**
|
|
984
|
+
* Background retry for a component whose start can fail (BOFF-17231).
|
|
985
|
+
*
|
|
986
|
+
* WHY THIS EXISTS
|
|
987
|
+
* Most services started their Redis Streams consumers once at boot, logged a
|
|
988
|
+
* failure and carried on. When Valkey was unreachable at that moment (on
|
|
989
|
+
* 2026-11-28 a pod booted while CoreDNS was still starting and got
|
|
990
|
+
* `getaddrinfo EAI_AGAIN`), the consumer stayed off for the life of the pod.
|
|
991
|
+
* Readiness never looked at it, so the pod served traffic while every event it
|
|
992
|
+
* should have consumed was silently dropped until the next restart.
|
|
993
|
+
*
|
|
994
|
+
* `superviseStart` runs the first attempt inline, so boot waits no longer than
|
|
995
|
+
* one attempt, and when it fails keeps retrying in the background with capped,
|
|
996
|
+
* equal-jitter exponential backoff (0.5 s growing to 30 s by default) until an
|
|
997
|
+
* attempt succeeds or `stop()` is called.
|
|
998
|
+
*
|
|
999
|
+
* - Every failed attempt is followed by `teardown()` (bounded by a timeout),
|
|
1000
|
+
* so a half-built consumer never leaks its connections across retries.
|
|
1001
|
+
* An attempt that hangs past `attemptTimeoutMs` counts as failed.
|
|
1002
|
+
* - `stop()` cancels a pending retry and waits for an attempt in flight; an
|
|
1003
|
+
* attempt that succeeds after `stop()` is torn down instead of left running.
|
|
1004
|
+
* - The supervisor registers with the process-wide consumer health registry,
|
|
1005
|
+
* which `createServer` reports as the optional `consumers` readiness
|
|
1006
|
+
* dependency and can feed to its liveness watchdog.
|
|
1007
|
+
* - Entering and leaving the degraded state is logged once each, and
|
|
1008
|
+
* exported as the `event_consumer_degraded` gauge plus the
|
|
1009
|
+
* `event_consumer_start_failures_total` counter.
|
|
1010
|
+
*
|
|
1011
|
+
* ```ts
|
|
1012
|
+
* const supervisor = superviseStart({
|
|
1013
|
+
* name: 'rbac.workspace-created',
|
|
1014
|
+
* start: () => consumer.startConsuming(),
|
|
1015
|
+
* teardown: () => consumer.stopConsuming(),
|
|
1016
|
+
* });
|
|
1017
|
+
* await supervisor.start(); // false = first attempt failed, retrying in the background
|
|
1018
|
+
* // shutdown: await supervisor.stop();
|
|
1019
|
+
* ```
|
|
1020
|
+
*/
|
|
1021
|
+
/** Default delay before the first retry. */
|
|
1022
|
+
const DEFAULT_START_RETRY_BASE_MS = 500;
|
|
1023
|
+
/** Default ceiling for the delay between retries. */
|
|
1024
|
+
const DEFAULT_START_RETRY_MAX_MS = 3e4;
|
|
1025
|
+
/** Default bound on one `teardown()` call. */
|
|
1026
|
+
const DEFAULT_START_TEARDOWN_TIMEOUT_MS = 5e3;
|
|
1027
|
+
/**
|
|
1028
|
+
* Default bound on one start attempt. ioredis queues commands while it
|
|
1029
|
+
* reconnects, so a connection lost between connect and subscribe could
|
|
1030
|
+
* otherwise hang an attempt, and with it every later retry, for good.
|
|
1031
|
+
*/
|
|
1032
|
+
const DEFAULT_START_ATTEMPT_TIMEOUT_MS = 6e4;
|
|
1033
|
+
function errorMessage$1(error) {
|
|
1034
|
+
return error instanceof Error ? error.message : String(error);
|
|
1035
|
+
}
|
|
1036
|
+
function positive(value, fallback) {
|
|
1037
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : fallback;
|
|
1038
|
+
}
|
|
1039
|
+
async function withTimeout(work, ms, label) {
|
|
1040
|
+
let timer;
|
|
1041
|
+
try {
|
|
1042
|
+
await Promise.race([Promise.resolve().then(work), new Promise((_, reject) => {
|
|
1043
|
+
timer = setTimeout(() => reject(/* @__PURE__ */ new Error(`${label} timed out after ${String(ms)}ms`)), ms);
|
|
1044
|
+
timer.unref?.();
|
|
1045
|
+
})]);
|
|
1046
|
+
} finally {
|
|
1047
|
+
if (timer) clearTimeout(timer);
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
function superviseStart(options) {
|
|
1051
|
+
const { name } = options;
|
|
1052
|
+
if (!name || name.trim() === "") throw new Error("[StartSupervisor] name is required");
|
|
1053
|
+
const baseMs = positive(options.retry?.initialDelayMs, 500);
|
|
1054
|
+
const maxMs = Math.max(baseMs, positive(options.retry?.maxDelayMs, DEFAULT_START_RETRY_MAX_MS));
|
|
1055
|
+
const random = options.retry?.random ?? Math.random;
|
|
1056
|
+
const teardownTimeoutMs = positive(options.teardownTimeoutMs, DEFAULT_START_TEARDOWN_TIMEOUT_MS);
|
|
1057
|
+
const attemptTimeoutMs = positive(options.attemptTimeoutMs, DEFAULT_START_ATTEMPT_TIMEOUT_MS);
|
|
1058
|
+
let state = "idle";
|
|
1059
|
+
/** True between a successful `options.start` and its teardown. */
|
|
1060
|
+
let live = false;
|
|
1061
|
+
let stopped = false;
|
|
1062
|
+
let attempts = 0;
|
|
1063
|
+
let consecutiveFailures = 0;
|
|
1064
|
+
let lastError = null;
|
|
1065
|
+
let degradedSince = null;
|
|
1066
|
+
let nextRetryAt = null;
|
|
1067
|
+
let timer = null;
|
|
1068
|
+
let firstAttempt = null;
|
|
1069
|
+
let inFlight = null;
|
|
1070
|
+
let unregisterHealth = null;
|
|
1071
|
+
const metricLabels = { consumer: name };
|
|
1072
|
+
function exportDegraded(degraded) {
|
|
1073
|
+
getMetricsRegistry().createGauge("event_consumer_degraded", "1 while a supervised event consumer is not started (its start failed and is being retried)").set(degraded ? 1 : 0, metricLabels);
|
|
1074
|
+
}
|
|
1075
|
+
function recordFailure() {
|
|
1076
|
+
getMetricsRegistry().createCounter("event_consumer_start_failures_total", "Failed start attempts of supervised event consumers").inc(metricLabels);
|
|
1077
|
+
}
|
|
1078
|
+
function isHealthy() {
|
|
1079
|
+
if (state !== "running") return false;
|
|
1080
|
+
return options.isHealthy ? options.isHealthy() : true;
|
|
1081
|
+
}
|
|
1082
|
+
function describe() {
|
|
1083
|
+
if (state === "running") return `${name}: running, transport disconnected`;
|
|
1084
|
+
if (consecutiveFailures > 0) return `${name}: ${state} after ${String(consecutiveFailures)} failed start(s)`;
|
|
1085
|
+
return `${name}: ${state}`;
|
|
1086
|
+
}
|
|
1087
|
+
const disposable = {
|
|
1088
|
+
shutdownName: `event-consumer-supervisor:${name}`,
|
|
1089
|
+
dispose: () => stop()
|
|
1090
|
+
};
|
|
1091
|
+
async function teardown(reason) {
|
|
1092
|
+
if (!options.teardown) return;
|
|
1093
|
+
try {
|
|
1094
|
+
await withTimeout(options.teardown, teardownTimeoutMs, `[StartSupervisor] ${name} teardown`);
|
|
1095
|
+
} catch (error) {
|
|
1096
|
+
logger.warn("[StartSupervisor] teardown failed", {
|
|
1097
|
+
consumer: name,
|
|
1098
|
+
reason,
|
|
1099
|
+
error: errorMessage$1(error)
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
function track(attempt) {
|
|
1104
|
+
inFlight = attempt;
|
|
1105
|
+
attempt.finally(() => {
|
|
1106
|
+
if (inFlight === attempt) inFlight = null;
|
|
1107
|
+
});
|
|
1108
|
+
return attempt;
|
|
1109
|
+
}
|
|
1110
|
+
function scheduleRetry() {
|
|
1111
|
+
const delayMs = computeBackoffMs(consecutiveFailures, baseMs, maxMs, random);
|
|
1112
|
+
nextRetryAt = Date.now() + delayMs;
|
|
1113
|
+
state = "retrying";
|
|
1114
|
+
timer = setTimeout(() => {
|
|
1115
|
+
timer = null;
|
|
1116
|
+
nextRetryAt = null;
|
|
1117
|
+
if (stopped) return;
|
|
1118
|
+
track(runAttempt());
|
|
1119
|
+
}, delayMs);
|
|
1120
|
+
logger.warn("[StartSupervisor] start failed; retrying in the background", {
|
|
1121
|
+
consumer: name,
|
|
1122
|
+
attempt: consecutiveFailures,
|
|
1123
|
+
delayMs,
|
|
1124
|
+
error: lastError
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
async function runAttempt() {
|
|
1128
|
+
attempts += 1;
|
|
1129
|
+
state = "starting";
|
|
1130
|
+
try {
|
|
1131
|
+
await withTimeout(options.start, attemptTimeoutMs, `[StartSupervisor] ${name} start`);
|
|
1132
|
+
} catch (error) {
|
|
1133
|
+
lastError = errorMessage$1(error);
|
|
1134
|
+
await teardown("failed start");
|
|
1135
|
+
if (stopped) return false;
|
|
1136
|
+
consecutiveFailures += 1;
|
|
1137
|
+
recordFailure();
|
|
1138
|
+
if (degradedSince === null) {
|
|
1139
|
+
degradedSince = Date.now();
|
|
1140
|
+
logger.error("[StartSupervisor] consumer degraded: its events are not consumed on this replica until a start succeeds", {
|
|
1141
|
+
consumer: name,
|
|
1142
|
+
error: lastError
|
|
1143
|
+
});
|
|
1144
|
+
exportDegraded(true);
|
|
1145
|
+
}
|
|
1146
|
+
scheduleRetry();
|
|
1147
|
+
return false;
|
|
1148
|
+
}
|
|
1149
|
+
live = true;
|
|
1150
|
+
if (stopped) return false;
|
|
1151
|
+
state = "running";
|
|
1152
|
+
if (degradedSince !== null) logger.info("[StartSupervisor] consumer recovered", {
|
|
1153
|
+
consumer: name,
|
|
1154
|
+
attempts: consecutiveFailures + 1,
|
|
1155
|
+
degradedForMs: Date.now() - degradedSince
|
|
1156
|
+
});
|
|
1157
|
+
consecutiveFailures = 0;
|
|
1158
|
+
degradedSince = null;
|
|
1159
|
+
exportDegraded(false);
|
|
1160
|
+
return true;
|
|
1161
|
+
}
|
|
1162
|
+
let stopping = null;
|
|
1163
|
+
function stop() {
|
|
1164
|
+
if (stopping) return stopping;
|
|
1165
|
+
if (stopped || state === "idle") return Promise.resolve();
|
|
1166
|
+
stopping = doStop().finally(() => {
|
|
1167
|
+
stopping = null;
|
|
1168
|
+
});
|
|
1169
|
+
return stopping;
|
|
1170
|
+
}
|
|
1171
|
+
async function doStop() {
|
|
1172
|
+
stopped = true;
|
|
1173
|
+
if (timer) {
|
|
1174
|
+
clearTimeout(timer);
|
|
1175
|
+
timer = null;
|
|
1176
|
+
}
|
|
1177
|
+
nextRetryAt = null;
|
|
1178
|
+
if (inFlight) await inFlight;
|
|
1179
|
+
if (live) {
|
|
1180
|
+
live = false;
|
|
1181
|
+
await teardown("stop");
|
|
1182
|
+
}
|
|
1183
|
+
state = "stopped";
|
|
1184
|
+
degradedSince = null;
|
|
1185
|
+
exportDegraded(false);
|
|
1186
|
+
unregisterHealth?.();
|
|
1187
|
+
unregisterHealth = null;
|
|
1188
|
+
unregisterDisposable(disposable);
|
|
1189
|
+
firstAttempt = null;
|
|
1190
|
+
}
|
|
1191
|
+
return {
|
|
1192
|
+
name,
|
|
1193
|
+
start() {
|
|
1194
|
+
if (firstAttempt) return firstAttempt;
|
|
1195
|
+
stopped = false;
|
|
1196
|
+
attempts = 0;
|
|
1197
|
+
consecutiveFailures = 0;
|
|
1198
|
+
lastError = null;
|
|
1199
|
+
unregisterHealth = registerConsumerHealthSource({
|
|
1200
|
+
name,
|
|
1201
|
+
isHealthy,
|
|
1202
|
+
describe
|
|
1203
|
+
});
|
|
1204
|
+
registerDisposable(disposable);
|
|
1205
|
+
firstAttempt = track(runAttempt());
|
|
1206
|
+
return firstAttempt;
|
|
1207
|
+
},
|
|
1208
|
+
stop,
|
|
1209
|
+
isRunning: () => state === "running",
|
|
1210
|
+
isHealthy,
|
|
1211
|
+
getStatus: () => ({
|
|
1212
|
+
name,
|
|
1213
|
+
state,
|
|
1214
|
+
attempts,
|
|
1215
|
+
consecutiveFailures,
|
|
1216
|
+
lastError,
|
|
1217
|
+
degradedSince,
|
|
1218
|
+
nextRetryAt
|
|
1219
|
+
})
|
|
1220
|
+
};
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
// src/event-queue/supervised-consumer.ts
|
|
1224
|
+
/**
|
|
1225
|
+
* A Redis Streams consumer whose start is retried until it succeeds
|
|
1226
|
+
* (BOFF-17231). See `start-supervisor.ts` for the retry, teardown and health
|
|
1227
|
+
* semantics.
|
|
1228
|
+
*
|
|
1229
|
+
* Each attempt builds a fresh consumer, connects it and runs `subscribe`. A
|
|
1230
|
+
* failed attempt disconnects that consumer (which also unsubscribes whatever
|
|
1231
|
+
* it had subscribed), so retries never accumulate connections.
|
|
1232
|
+
*
|
|
1233
|
+
* ```ts
|
|
1234
|
+
* const workspaceEvents = createSupervisedConsumer({
|
|
1235
|
+
* name: 'rbac.workspace-created',
|
|
1236
|
+
* stream: 'WORKSPACE_EVENTS',
|
|
1237
|
+
* group: 'wspace-rbac-svc',
|
|
1238
|
+
* subscribe: async (consumer) => {
|
|
1239
|
+
* await consumer.subscribe({ subject: 'workspace.created', handler, options: { ackPolicy: 'explicit' } });
|
|
1240
|
+
* },
|
|
1241
|
+
* });
|
|
1242
|
+
* await workspaceEvents.start(); // never throws; false = retrying in the background
|
|
1243
|
+
* // shutdown: await workspaceEvents.stop();
|
|
1244
|
+
* ```
|
|
1245
|
+
*/
|
|
1246
|
+
function createSupervisedConsumer(options) {
|
|
1247
|
+
let create;
|
|
1248
|
+
if (options.create) create = options.create;
|
|
1249
|
+
else {
|
|
1250
|
+
const { stream, group } = options;
|
|
1251
|
+
if (!stream || !group) throw new Error(`[SupervisedConsumer] ${options.name}: either create or both stream and group are required`);
|
|
1252
|
+
create = () => createConsumer(stream, group);
|
|
1253
|
+
}
|
|
1254
|
+
/** The consumer of the current attempt, kept until it is torn down. */
|
|
1255
|
+
let current = null;
|
|
1256
|
+
let running = null;
|
|
1257
|
+
const supervisor = superviseStart({
|
|
1258
|
+
name: options.name,
|
|
1259
|
+
start: async () => {
|
|
1260
|
+
const consumer = create();
|
|
1261
|
+
current = consumer;
|
|
1262
|
+
await consumer.connect();
|
|
1263
|
+
await options.subscribe(consumer);
|
|
1264
|
+
if (current !== consumer) {
|
|
1265
|
+
await consumer.disconnect();
|
|
1266
|
+
throw new Error(`[SupervisedConsumer] ${options.name}: superseded start attempt`);
|
|
1267
|
+
}
|
|
1268
|
+
running = consumer;
|
|
1269
|
+
},
|
|
1270
|
+
teardown: async () => {
|
|
1271
|
+
const consumer = current;
|
|
1272
|
+
current = null;
|
|
1273
|
+
running = null;
|
|
1274
|
+
if (consumer) await consumer.disconnect();
|
|
1275
|
+
},
|
|
1276
|
+
isHealthy: () => running?.isConnected() ?? false,
|
|
1277
|
+
...options.retry ? { retry: options.retry } : {},
|
|
1278
|
+
...options.teardownTimeoutMs ? { teardownTimeoutMs: options.teardownTimeoutMs } : {},
|
|
1279
|
+
...options.attemptTimeoutMs ? { attemptTimeoutMs: options.attemptTimeoutMs } : {}
|
|
1280
|
+
});
|
|
1281
|
+
return {
|
|
1282
|
+
...supervisor,
|
|
1283
|
+
getConsumer: () => supervisor.isRunning() ? running : null
|
|
1284
|
+
};
|
|
1285
|
+
}
|
|
1286
|
+
|
|
979
1287
|
// src/event-queue/lifecycle-consumer.ts
|
|
980
1288
|
/**
|
|
981
1289
|
* Platform lifecycle consumer (registry PR-EVT-06, PR-BE-24).
|
|
@@ -1327,6 +1635,10 @@ function createLifecycleConsumer(options) {
|
|
|
1327
1635
|
|
|
1328
1636
|
// src/event-queue/index.ts
|
|
1329
1637
|
var event_queue_exports = /* @__PURE__ */ __exportAll({
|
|
1638
|
+
DEFAULT_START_ATTEMPT_TIMEOUT_MS: () => DEFAULT_START_ATTEMPT_TIMEOUT_MS,
|
|
1639
|
+
DEFAULT_START_RETRY_BASE_MS: () => 500,
|
|
1640
|
+
DEFAULT_START_RETRY_MAX_MS: () => DEFAULT_START_RETRY_MAX_MS,
|
|
1641
|
+
DEFAULT_START_TEARDOWN_TIMEOUT_MS: () => DEFAULT_START_TEARDOWN_TIMEOUT_MS,
|
|
1330
1642
|
EVENT_STREAMS_URL_ENV_KEYS: () => EVENT_STREAMS_URL_ENV_KEYS,
|
|
1331
1643
|
EVENT_TAXONOMY_BRAND: () => EVENT_TAXONOMY_BRAND,
|
|
1332
1644
|
EventPriority: () => EventPriority,
|
|
@@ -1349,6 +1661,7 @@ var event_queue_exports = /* @__PURE__ */ __exportAll({
|
|
|
1349
1661
|
RedisStreamsEventPublisher: () => RedisStreamsEventPublisher,
|
|
1350
1662
|
WSPACE_GRAPH_EVENTS_STREAM: () => WSPACE_GRAPH_EVENTS_STREAM,
|
|
1351
1663
|
buildConsumerGroupName: () => buildConsumerGroupName,
|
|
1664
|
+
computeBackoffMs: () => computeBackoffMs,
|
|
1352
1665
|
createConsumer: () => createConsumer,
|
|
1353
1666
|
createEventsManagerSingleton: () => createEventsManagerSingleton,
|
|
1354
1667
|
createGraphEventEmitter: () => createGraphEventEmitter,
|
|
@@ -1358,9 +1671,11 @@ var event_queue_exports = /* @__PURE__ */ __exportAll({
|
|
|
1358
1671
|
createMemoryPublisher: () => createMemoryPublisher,
|
|
1359
1672
|
createModuleEventsService: () => createModuleEventsService,
|
|
1360
1673
|
createPublisher: () => createPublisher,
|
|
1674
|
+
createSupervisedConsumer: () => createSupervisedConsumer,
|
|
1361
1675
|
defineEventTaxonomy: () => defineEventTaxonomy,
|
|
1362
1676
|
eventKeyScopeForUrl: () => eventKeyScopeForUrl,
|
|
1363
1677
|
eventSpec: () => eventSpec,
|
|
1678
|
+
getConsumerHealth: () => getConsumerHealth,
|
|
1364
1679
|
getGraphEventEmitter: () => getGraphEventEmitter,
|
|
1365
1680
|
isDefinedEventTaxonomy: () => isDefinedEventTaxonomy,
|
|
1366
1681
|
mergeEventTaxonomies: () => mergeEventTaxonomies,
|
|
@@ -1371,14 +1686,16 @@ var event_queue_exports = /* @__PURE__ */ __exportAll({
|
|
|
1371
1686
|
publishTaxonomyEvent: () => publishTaxonomyEvent,
|
|
1372
1687
|
redisDlqKey: () => dlqKey,
|
|
1373
1688
|
redisStreamKey: () => streamKey,
|
|
1689
|
+
registerConsumerHealthSource: () => registerConsumerHealthSource,
|
|
1374
1690
|
resetGraphEventEmitter: () => resetGraphEventEmitter,
|
|
1375
1691
|
resolveEventStreamsUrl: () => resolveEventStreamsUrl,
|
|
1376
1692
|
resolveEventStreamsUrlSource: () => resolveEventStreamsUrlSource,
|
|
1377
1693
|
resolveGraphEventsUrl: () => resolveGraphEventsUrl,
|
|
1378
1694
|
resolveGraphEventsUrlSource: () => resolveGraphEventsUrlSource,
|
|
1695
|
+
superviseStart: () => superviseStart,
|
|
1379
1696
|
taxonomyEventNames: () => taxonomyEventNames,
|
|
1380
1697
|
taxonomyNameViolation: () => taxonomyNameViolation
|
|
1381
1698
|
});
|
|
1382
1699
|
|
|
1383
|
-
export {
|
|
1384
|
-
//# sourceMappingURL=event-queue-
|
|
1700
|
+
export { EventPriority as A, isDefinedEventTaxonomy as C, taxonomyNameViolation as D, taxonomyEventNames as E, ModuleEventsService as M, createModuleEventsService as N, createConsumer as O, eventSpec as S, publishTaxonomyEvent as T, EVENT_TAXONOMY_BRAND as _, parseOrganizationDeleted as a, WSPACE_GRAPH_EVENTS_STREAM as b, parseWorkspaceMemberRemoved as c, DEFAULT_START_RETRY_BASE_MS as d, DEFAULT_START_RETRY_MAX_MS as f, createEventsManagerSingleton as g, EventsManager as h, createLifecycleConsumer as i, EventsModule as j, createPublisher as k, createSupervisedConsumer as l, superviseStart as m, LIFECYCLE_SUBJECTS as n, parseWorkspaceDeletedGraph as o, DEFAULT_START_TEARDOWN_TIMEOUT_MS as p, buildConsumerGroupName as r, parseWorkspaceDeletedStream as s, event_queue_exports as t, DEFAULT_START_ATTEMPT_TIMEOUT_MS as u, PLATFORM_EVENT_TAXONOMY as v, mergeEventTaxonomies as w, defineEventTaxonomy as x, REFERENCE_PRODUCT_EVENT_TAXONOMY as y };
|
|
1701
|
+
//# sourceMappingURL=event-queue-C58O9KEG.js.map
|