nvent 0.4.4 → 0.5.0
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/module.d.mts +4 -185
- package/dist/module.json +3 -3
- package/dist/module.mjs +451 -257
- package/dist/runtime/adapters/base/index.d.ts +6 -0
- package/dist/runtime/adapters/base/index.js +1 -0
- package/dist/runtime/adapters/base/store-validator.d.ts +48 -0
- package/dist/runtime/adapters/base/store-validator.js +147 -0
- package/dist/runtime/adapters/builtin/file-queue.d.ts +67 -0
- package/dist/runtime/adapters/builtin/file-queue.js +499 -0
- package/dist/runtime/adapters/builtin/file-store.d.ts +32 -0
- package/dist/runtime/adapters/builtin/file-store.js +206 -0
- package/dist/runtime/adapters/builtin/file-stream.d.ts +39 -0
- package/dist/runtime/adapters/builtin/file-stream.js +56 -0
- package/dist/runtime/adapters/builtin/index.d.ts +10 -0
- package/dist/runtime/adapters/builtin/index.js +5 -0
- package/dist/runtime/adapters/builtin/memory-queue.d.ts +52 -0
- package/dist/runtime/adapters/builtin/memory-queue.js +243 -0
- package/dist/runtime/adapters/builtin/memory-store.d.ts +68 -0
- package/dist/runtime/adapters/builtin/memory-store.js +333 -0
- package/dist/runtime/adapters/builtin/memory-stream.d.ts +21 -0
- package/dist/runtime/adapters/builtin/memory-stream.js +56 -0
- package/dist/runtime/adapters/factory.d.ts +31 -0
- package/dist/runtime/adapters/factory.js +134 -0
- package/dist/runtime/adapters/index.d.ts +8 -0
- package/dist/runtime/adapters/index.js +3 -0
- package/dist/runtime/adapters/interfaces/index.d.ts +11 -0
- package/dist/runtime/adapters/interfaces/index.js +3 -0
- package/dist/runtime/adapters/interfaces/queue.d.ts +150 -0
- package/dist/runtime/adapters/interfaces/store.d.ts +297 -0
- package/dist/runtime/adapters/interfaces/stream.d.ts +62 -0
- package/dist/runtime/adapters/registry.d.ts +85 -0
- package/dist/runtime/adapters/registry.js +161 -0
- package/dist/runtime/config/index.d.ts +29 -0
- package/dist/runtime/config/index.js +175 -0
- package/dist/runtime/config/types.d.ts +397 -0
- package/dist/runtime/config/types.js +0 -0
- package/dist/runtime/{server-utils/events → events}/eventBus.d.ts +1 -1
- package/dist/runtime/events/types.d.ts +145 -0
- package/dist/runtime/events/types.js +0 -0
- package/dist/runtime/events/utils/scheduleTrigger.d.ts +8 -0
- package/dist/runtime/events/utils/scheduleTrigger.js +69 -0
- package/dist/runtime/events/utils/stallDetector.d.ts +140 -0
- package/dist/runtime/events/utils/stallDetector.js +436 -0
- package/dist/runtime/events/utils/triggerRuntime.d.ts +58 -0
- package/dist/runtime/events/utils/triggerRuntime.js +212 -0
- package/dist/runtime/{server-utils/events → events}/wiring/flowWiring.d.ts +12 -11
- package/dist/runtime/events/wiring/flowWiring.js +1020 -0
- package/dist/runtime/events/wiring/registry.d.ts +19 -0
- package/dist/runtime/events/wiring/registry.js +35 -0
- package/dist/runtime/events/wiring/stateWiring.d.ts +37 -0
- package/dist/runtime/events/wiring/stateWiring.js +92 -0
- package/dist/runtime/events/wiring/streamWiring.d.ts +36 -0
- package/dist/runtime/events/wiring/streamWiring.js +156 -0
- package/dist/runtime/events/wiring/triggerWiring.d.ts +21 -0
- package/dist/runtime/events/wiring/triggerWiring.js +412 -0
- package/dist/runtime/nitro/plugins/00.adapters.d.ts +14 -0
- package/dist/runtime/nitro/plugins/00.adapters.js +73 -0
- package/dist/runtime/nitro/plugins/02.workers.js +63 -0
- package/dist/runtime/nitro/plugins/03.triggers.d.ts +12 -0
- package/dist/runtime/nitro/plugins/03.triggers.js +55 -0
- package/dist/runtime/nitro/routes/webhook.await.d.ts +23 -0
- package/dist/runtime/nitro/routes/webhook.await.js +90 -0
- package/dist/runtime/nitro/routes/webhook.trigger.d.ts +69 -0
- package/dist/runtime/nitro/routes/webhook.trigger.js +64 -0
- package/dist/runtime/nitro/utils/adapters.d.ts +66 -0
- package/dist/runtime/nitro/utils/adapters.js +51 -0
- package/dist/runtime/nitro/utils/awaitPatterns/event.d.ts +15 -0
- package/dist/runtime/nitro/utils/awaitPatterns/event.js +120 -0
- package/dist/runtime/nitro/utils/awaitPatterns/index.d.ts +28 -0
- package/dist/runtime/nitro/utils/awaitPatterns/index.js +55 -0
- package/dist/runtime/nitro/utils/awaitPatterns/schedule.d.ts +16 -0
- package/dist/runtime/nitro/utils/awaitPatterns/schedule.js +78 -0
- package/dist/runtime/nitro/utils/awaitPatterns/time.d.ts +15 -0
- package/dist/runtime/nitro/utils/awaitPatterns/time.js +67 -0
- package/dist/runtime/nitro/utils/awaitPatterns/webhook.d.ts +15 -0
- package/dist/runtime/nitro/utils/awaitPatterns/webhook.js +120 -0
- package/dist/runtime/nitro/utils/defineFunction.d.ts +10 -0
- package/dist/runtime/nitro/utils/defineFunction.js +17 -0
- package/dist/runtime/nitro/utils/defineFunctionConfig.d.ts +310 -0
- package/dist/runtime/nitro/utils/defineFunctionConfig.js +3 -0
- package/dist/runtime/nitro/utils/defineHooks.d.ts +41 -0
- package/dist/runtime/nitro/utils/defineHooks.js +6 -0
- package/dist/runtime/nitro/utils/registerAdapter.d.ts +59 -0
- package/dist/runtime/nitro/utils/registerAdapter.js +13 -0
- package/dist/runtime/nitro/utils/useAwait.d.ts +71 -0
- package/dist/runtime/nitro/utils/useAwait.js +139 -0
- package/dist/runtime/{server-utils → nitro}/utils/useEventManager.d.ts +2 -2
- package/dist/runtime/{server-utils → nitro}/utils/useEventManager.js +1 -1
- package/dist/runtime/nitro/utils/useFlow.d.ts +68 -0
- package/dist/runtime/nitro/utils/useFlow.js +226 -0
- package/dist/runtime/nitro/utils/useHookRegistry.d.ts +34 -0
- package/dist/runtime/nitro/utils/useHookRegistry.js +25 -0
- package/dist/runtime/{server-utils → nitro}/utils/useNventLogger.js +2 -2
- package/dist/runtime/nitro/utils/useRunContext.d.ts +6 -0
- package/dist/runtime/nitro/utils/useRunContext.js +102 -0
- package/dist/runtime/nitro/utils/useStreamTopics.d.ts +83 -0
- package/dist/runtime/nitro/utils/useStreamTopics.js +94 -0
- package/dist/runtime/nitro/utils/useTrigger.d.ts +150 -0
- package/dist/runtime/nitro/utils/useTrigger.js +320 -0
- package/dist/runtime/scheduler/index.d.ts +33 -0
- package/dist/runtime/scheduler/index.js +38 -0
- package/dist/runtime/scheduler/scheduler.d.ts +113 -0
- package/dist/runtime/scheduler/scheduler.js +623 -0
- package/dist/runtime/scheduler/types.d.ts +116 -0
- package/dist/runtime/scheduler/types.js +0 -0
- package/dist/runtime/tsconfig.json +8 -0
- package/dist/runtime/worker/node/runner.d.ts +53 -0
- package/dist/runtime/worker/node/runner.js +327 -0
- package/dist/types.d.mts +2 -2
- package/package.json +16 -46
- package/LICENSE +0 -21
- package/README.md +0 -389
- package/dist/runtime/app/assets/vueflow.css +0 -1
- package/dist/runtime/app/components/ConfirmDialog.d.vue.ts +0 -33
- package/dist/runtime/app/components/ConfirmDialog.vue +0 -121
- package/dist/runtime/app/components/ConfirmDialog.vue.d.ts +0 -33
- package/dist/runtime/app/components/FlowDiagram.d.vue.ts +0 -64
- package/dist/runtime/app/components/FlowDiagram.vue +0 -338
- package/dist/runtime/app/components/FlowDiagram.vue.d.ts +0 -64
- package/dist/runtime/app/components/FlowNodeCard.d.vue.ts +0 -29
- package/dist/runtime/app/components/FlowNodeCard.vue +0 -156
- package/dist/runtime/app/components/FlowNodeCard.vue.d.ts +0 -29
- package/dist/runtime/app/components/FlowRunOverview.d.vue.ts +0 -9
- package/dist/runtime/app/components/FlowRunOverview.vue +0 -291
- package/dist/runtime/app/components/FlowRunOverview.vue.d.ts +0 -9
- package/dist/runtime/app/components/FlowRunStatusBadge.d.vue.ts +0 -14
- package/dist/runtime/app/components/FlowRunStatusBadge.vue +0 -60
- package/dist/runtime/app/components/FlowRunStatusBadge.vue.d.ts +0 -14
- package/dist/runtime/app/components/FlowRunTimeline.d.vue.ts +0 -12
- package/dist/runtime/app/components/FlowRunTimeline.vue +0 -127
- package/dist/runtime/app/components/FlowRunTimeline.vue.d.ts +0 -12
- package/dist/runtime/app/components/FlowScheduleDialog.d.vue.ts +0 -16
- package/dist/runtime/app/components/FlowScheduleDialog.vue +0 -226
- package/dist/runtime/app/components/FlowScheduleDialog.vue.d.ts +0 -16
- package/dist/runtime/app/components/FlowSchedulesList.d.vue.ts +0 -12
- package/dist/runtime/app/components/FlowSchedulesList.vue +0 -99
- package/dist/runtime/app/components/FlowSchedulesList.vue.d.ts +0 -12
- package/dist/runtime/app/components/JobScheduling.d.vue.ts +0 -6
- package/dist/runtime/app/components/JobScheduling.vue +0 -203
- package/dist/runtime/app/components/JobScheduling.vue.d.ts +0 -6
- package/dist/runtime/app/components/ListItem.d.vue.ts +0 -23
- package/dist/runtime/app/components/ListItem.vue +0 -70
- package/dist/runtime/app/components/ListItem.vue.d.ts +0 -23
- package/dist/runtime/app/components/QueueConfigDetails.d.vue.ts +0 -45
- package/dist/runtime/app/components/QueueConfigDetails.vue +0 -412
- package/dist/runtime/app/components/QueueConfigDetails.vue.d.ts +0 -45
- package/dist/runtime/app/components/StatCounter.d.vue.ts +0 -9
- package/dist/runtime/app/components/StatCounter.vue +0 -25
- package/dist/runtime/app/components/StatCounter.vue.d.ts +0 -9
- package/dist/runtime/app/components/TimelineList.d.vue.ts +0 -7
- package/dist/runtime/app/components/TimelineList.vue +0 -210
- package/dist/runtime/app/components/TimelineList.vue.d.ts +0 -7
- package/dist/runtime/app/components/nhealth/component-router.d.vue.ts +0 -46
- package/dist/runtime/app/components/nhealth/component-router.vue +0 -26
- package/dist/runtime/app/components/nhealth/component-router.vue.d.ts +0 -46
- package/dist/runtime/app/components/nhealth/component-shell.d.vue.ts +0 -24
- package/dist/runtime/app/components/nhealth/component-shell.vue +0 -89
- package/dist/runtime/app/components/nhealth/component-shell.vue.d.ts +0 -24
- package/dist/runtime/app/composables/useAnalyzedFlows.d.ts +0 -14
- package/dist/runtime/app/composables/useAnalyzedFlows.js +0 -8
- package/dist/runtime/app/composables/useComponentRouter.d.ts +0 -38
- package/dist/runtime/app/composables/useComponentRouter.js +0 -240
- package/dist/runtime/app/composables/useFlowRunTimeline.d.ts +0 -80
- package/dist/runtime/app/composables/useFlowRunTimeline.js +0 -68
- package/dist/runtime/app/composables/useFlowRuns.d.ts +0 -18
- package/dist/runtime/app/composables/useFlowRuns.js +0 -32
- package/dist/runtime/app/composables/useFlowRunsInfinite.d.ts +0 -24
- package/dist/runtime/app/composables/useFlowRunsInfinite.js +0 -123
- package/dist/runtime/app/composables/useFlowRunsPolling.d.ts +0 -9
- package/dist/runtime/app/composables/useFlowRunsPolling.js +0 -33
- package/dist/runtime/app/composables/useFlowState.d.ts +0 -125
- package/dist/runtime/app/composables/useFlowState.js +0 -211
- package/dist/runtime/app/composables/useFlowWebSocket.d.ts +0 -27
- package/dist/runtime/app/composables/useFlowWebSocket.js +0 -205
- package/dist/runtime/app/composables/useFlowsNavigation.d.ts +0 -10
- package/dist/runtime/app/composables/useFlowsNavigation.js +0 -58
- package/dist/runtime/app/composables/useQueueJobs.d.ts +0 -26
- package/dist/runtime/app/composables/useQueueJobs.js +0 -20
- package/dist/runtime/app/composables/useQueueUpdates.d.ts +0 -26
- package/dist/runtime/app/composables/useQueueUpdates.js +0 -122
- package/dist/runtime/app/composables/useQueues.d.ts +0 -45
- package/dist/runtime/app/composables/useQueues.js +0 -26
- package/dist/runtime/app/composables/useQueuesLive.d.ts +0 -19
- package/dist/runtime/app/composables/useQueuesLive.js +0 -143
- package/dist/runtime/app/pages/flows/index.d.vue.ts +0 -3
- package/dist/runtime/app/pages/flows/index.vue +0 -645
- package/dist/runtime/app/pages/flows/index.vue.d.ts +0 -3
- package/dist/runtime/app/pages/index.d.vue.ts +0 -3
- package/dist/runtime/app/pages/index.vue +0 -34
- package/dist/runtime/app/pages/index.vue.d.ts +0 -3
- package/dist/runtime/app/pages/queues/index.d.vue.ts +0 -3
- package/dist/runtime/app/pages/queues/index.vue +0 -229
- package/dist/runtime/app/pages/queues/index.vue.d.ts +0 -3
- package/dist/runtime/app/pages/queues/job.d.vue.ts +0 -3
- package/dist/runtime/app/pages/queues/job.vue +0 -262
- package/dist/runtime/app/pages/queues/job.vue.d.ts +0 -3
- package/dist/runtime/app/pages/queues/jobs.d.vue.ts +0 -3
- package/dist/runtime/app/pages/queues/jobs.vue +0 -291
- package/dist/runtime/app/pages/queues/jobs.vue.d.ts +0 -3
- package/dist/runtime/app/plugins/vueflow.client.d.ts +0 -2
- package/dist/runtime/app/plugins/vueflow.client.js +0 -11
- package/dist/runtime/constants.d.ts +0 -11
- package/dist/runtime/constants.js +0 -11
- package/dist/runtime/schema.d.ts +0 -37
- package/dist/runtime/schema.js +0 -20
- package/dist/runtime/server/api/_flows/[name]/clear-history.delete.d.ts +0 -10
- package/dist/runtime/server/api/_flows/[name]/clear-history.delete.js +0 -44
- package/dist/runtime/server/api/_flows/[name]/runs.get.d.ts +0 -7
- package/dist/runtime/server/api/_flows/[name]/runs.get.js +0 -53
- package/dist/runtime/server/api/_flows/[name]/schedule.post.js +0 -57
- package/dist/runtime/server/api/_flows/[name]/schedules/[id].delete.d.ts +0 -2
- package/dist/runtime/server/api/_flows/[name]/schedules/[id].delete.js +0 -42
- package/dist/runtime/server/api/_flows/[name]/schedules.get.d.ts +0 -2
- package/dist/runtime/server/api/_flows/[name]/schedules.get.js +0 -48
- package/dist/runtime/server/api/_flows/[name]/start.post.d.ts +0 -2
- package/dist/runtime/server/api/_flows/[name]/start.post.js +0 -9
- package/dist/runtime/server/api/_flows/index.get.d.ts +0 -6
- package/dist/runtime/server/api/_flows/index.get.js +0 -5
- package/dist/runtime/server/api/_flows/ws.d.ts +0 -60
- package/dist/runtime/server/api/_flows/ws.js +0 -188
- package/dist/runtime/server/api/_queues/[name]/job/[id].get.d.ts +0 -2
- package/dist/runtime/server/api/_queues/[name]/job/[id].get.js +0 -9
- package/dist/runtime/server/api/_queues/[name]/job/index.get.d.ts +0 -2
- package/dist/runtime/server/api/_queues/[name]/job/index.get.js +0 -18
- package/dist/runtime/server/api/_queues/index.get.d.ts +0 -2
- package/dist/runtime/server/api/_queues/index.get.js +0 -63
- package/dist/runtime/server/api/_queues/ws.d.ts +0 -48
- package/dist/runtime/server/api/_queues/ws.js +0 -205
- package/dist/runtime/server/plugins/00.event-store.d.ts +0 -13
- package/dist/runtime/server/plugins/00.event-store.js +0 -16
- package/dist/runtime/server/plugins/flow-management.d.ts +0 -13
- package/dist/runtime/server/plugins/flow-management.js +0 -65
- package/dist/runtime/server/plugins/queue-management.d.ts +0 -2
- package/dist/runtime/server/plugins/queue-management.js +0 -27
- package/dist/runtime/server/plugins/state-cleanup.d.ts +0 -11
- package/dist/runtime/server/plugins/state-cleanup.js +0 -93
- package/dist/runtime/server/plugins/worker-management.d.ts +0 -2
- package/dist/runtime/server/plugins/worker-management.js +0 -33
- package/dist/runtime/server/tsconfig.json +0 -3
- package/dist/runtime/server-utils/events/adapters/fileAdapter.d.ts +0 -2
- package/dist/runtime/server-utils/events/adapters/fileAdapter.js +0 -382
- package/dist/runtime/server-utils/events/adapters/memoryAdapter.d.ts +0 -2
- package/dist/runtime/server-utils/events/adapters/memoryAdapter.js +0 -171
- package/dist/runtime/server-utils/events/adapters/redis/redisAdapter.d.ts +0 -2
- package/dist/runtime/server-utils/events/adapters/redis/redisAdapter.js +0 -348
- package/dist/runtime/server-utils/events/adapters/redis/redisPubSubGateway.d.ts +0 -30
- package/dist/runtime/server-utils/events/adapters/redis/redisPubSubGateway.js +0 -82
- package/dist/runtime/server-utils/events/eventStoreFactory.d.ts +0 -19
- package/dist/runtime/server-utils/events/eventStoreFactory.js +0 -44
- package/dist/runtime/server-utils/events/streamNames.d.ts +0 -17
- package/dist/runtime/server-utils/events/streamNames.js +0 -17
- package/dist/runtime/server-utils/events/types.d.ts +0 -63
- package/dist/runtime/server-utils/events/wiring/flowWiring.js +0 -409
- package/dist/runtime/server-utils/events/wiring/registry.d.ts +0 -10
- package/dist/runtime/server-utils/events/wiring/registry.js +0 -24
- package/dist/runtime/server-utils/queue/adapters/bullmq.d.ts +0 -18
- package/dist/runtime/server-utils/queue/adapters/bullmq.js +0 -164
- package/dist/runtime/server-utils/queue/queueFactory.d.ts +0 -3
- package/dist/runtime/server-utils/queue/queueFactory.js +0 -10
- package/dist/runtime/server-utils/queue/types.d.ts +0 -47
- package/dist/runtime/server-utils/state/adapters/redis.d.ts +0 -2
- package/dist/runtime/server-utils/state/adapters/redis.js +0 -42
- package/dist/runtime/server-utils/state/stateFactory.d.ts +0 -3
- package/dist/runtime/server-utils/state/stateFactory.js +0 -17
- package/dist/runtime/server-utils/state/types.d.ts +0 -23
- package/dist/runtime/server-utils/utils/defineQueueConfig.d.ts +0 -154
- package/dist/runtime/server-utils/utils/defineQueueConfig.js +0 -2
- package/dist/runtime/server-utils/utils/defineQueueWorker.d.ts +0 -10
- package/dist/runtime/server-utils/utils/defineQueueWorker.js +0 -17
- package/dist/runtime/server-utils/utils/useEventStore.d.ts +0 -20
- package/dist/runtime/server-utils/utils/useEventStore.js +0 -119
- package/dist/runtime/server-utils/utils/useFlowEngine.d.ts +0 -9
- package/dist/runtime/server-utils/utils/useFlowEngine.js +0 -44
- package/dist/runtime/server-utils/utils/useLogs.d.ts +0 -41
- package/dist/runtime/server-utils/utils/useLogs.js +0 -74
- package/dist/runtime/server-utils/utils/useQueue.d.ts +0 -31
- package/dist/runtime/server-utils/utils/useQueue.js +0 -24
- package/dist/runtime/server-utils/worker/adapter.d.ts +0 -4
- package/dist/runtime/server-utils/worker/adapter.js +0 -66
- package/dist/runtime/server-utils/worker/runner/node.d.ts +0 -27
- package/dist/runtime/server-utils/worker/runner/node.js +0 -196
- package/dist/runtime/types.d.ts +0 -132
- /package/dist/runtime/{server-utils/events/types.js → adapters/interfaces/queue.js} +0 -0
- /package/dist/runtime/{server-utils/queue/types.js → adapters/interfaces/store.js} +0 -0
- /package/dist/runtime/{server-utils/state/types.js → adapters/interfaces/stream.js} +0 -0
- /package/dist/runtime/{server-utils/events → events}/eventBus.js +0 -0
- /package/dist/runtime/{server/plugins/00.ws-lifecycle.d.ts → nitro/plugins/01.ws-lifecycle.d.ts} +0 -0
- /package/dist/runtime/{server/plugins/00.ws-lifecycle.js → nitro/plugins/01.ws-lifecycle.js} +0 -0
- /package/dist/runtime/{server/api/_flows/[name]/schedule.post.d.ts → nitro/plugins/02.workers.d.ts} +0 -0
- /package/dist/runtime/{server-utils → nitro}/utils/useNventLogger.d.ts +0 -0
- /package/dist/runtime/{server-utils → nitro}/utils/wsPeerManager.d.ts +0 -0
- /package/dist/runtime/{server-utils → nitro}/utils/wsPeerManager.js +0 -0
- /package/dist/runtime/{python → worker/python}/get_config.py +0 -0
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
const GLOBAL_KEY = "__nuxt_queue_memory_adapter__";
|
|
2
|
-
function getStore() {
|
|
3
|
-
if (!globalThis[GLOBAL_KEY]) {
|
|
4
|
-
globalThis[GLOBAL_KEY] = {
|
|
5
|
-
events: /* @__PURE__ */ new Map(),
|
|
6
|
-
listeners: /* @__PURE__ */ new Map(),
|
|
7
|
-
indices: /* @__PURE__ */ new Map()
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
return globalThis[GLOBAL_KEY];
|
|
11
|
-
}
|
|
12
|
-
export function createMemoryAdapter() {
|
|
13
|
-
const { events, listeners, indices } = getStore();
|
|
14
|
-
return {
|
|
15
|
-
async append(stream, e) {
|
|
16
|
-
const id = `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
17
|
-
const rec = { ...e, id, ts: (/* @__PURE__ */ new Date()).toISOString() };
|
|
18
|
-
const list = events.get(stream) || [];
|
|
19
|
-
list.push(rec);
|
|
20
|
-
events.set(stream, list);
|
|
21
|
-
const set = listeners.get(stream);
|
|
22
|
-
if (set) set.forEach((cb) => cb(rec));
|
|
23
|
-
return rec;
|
|
24
|
-
},
|
|
25
|
-
async read(stream, opts) {
|
|
26
|
-
const list = events.get(stream) || [];
|
|
27
|
-
const dir = opts?.direction || "forward";
|
|
28
|
-
if (dir === "backward") {
|
|
29
|
-
let end = list.length;
|
|
30
|
-
if (opts?.fromId) {
|
|
31
|
-
const idx2 = list.findIndex((e) => e.id === opts.fromId);
|
|
32
|
-
end = idx2 >= 0 ? idx2 : list.length;
|
|
33
|
-
}
|
|
34
|
-
const count = opts?.limit && opts.limit > 0 ? opts.limit : end;
|
|
35
|
-
const start = Math.max(0, end - count);
|
|
36
|
-
const slice = list.slice(start, end);
|
|
37
|
-
return slice.reverse();
|
|
38
|
-
}
|
|
39
|
-
if (!opts?.fromId) {
|
|
40
|
-
if (opts?.limit && opts.limit > 0) return list.slice(0, opts.limit);
|
|
41
|
-
return list;
|
|
42
|
-
}
|
|
43
|
-
const idx = list.findIndex((e) => e.id === opts.fromId);
|
|
44
|
-
const out = idx >= 0 ? list.slice(idx + 1) : list;
|
|
45
|
-
if (opts?.limit && opts.limit > 0) return out.slice(0, opts.limit);
|
|
46
|
-
return out;
|
|
47
|
-
},
|
|
48
|
-
async subscribe(stream, onEvent) {
|
|
49
|
-
let set = listeners.get(stream);
|
|
50
|
-
if (!set) {
|
|
51
|
-
set = /* @__PURE__ */ new Set();
|
|
52
|
-
listeners.set(stream, set);
|
|
53
|
-
}
|
|
54
|
-
set.add(onEvent);
|
|
55
|
-
return {
|
|
56
|
-
unsubscribe() {
|
|
57
|
-
set.delete(onEvent);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
},
|
|
61
|
-
async indexAdd(key, id, score, metadata) {
|
|
62
|
-
const data = indices.get(key) || [];
|
|
63
|
-
const existing = data.findIndex((entry) => entry.id === id);
|
|
64
|
-
if (existing >= 0) {
|
|
65
|
-
data[existing].score = score;
|
|
66
|
-
if (metadata) {
|
|
67
|
-
data[existing].metadata = metadata;
|
|
68
|
-
}
|
|
69
|
-
} else {
|
|
70
|
-
data.push({ id, score, metadata });
|
|
71
|
-
}
|
|
72
|
-
indices.set(key, data);
|
|
73
|
-
},
|
|
74
|
-
async indexRead(key, opts) {
|
|
75
|
-
const data = indices.get(key) || [];
|
|
76
|
-
const sorted = [...data].sort((a, b) => b.score - a.score);
|
|
77
|
-
const offset = opts?.offset || 0;
|
|
78
|
-
const limit = opts?.limit || 50;
|
|
79
|
-
return sorted.slice(offset, offset + limit);
|
|
80
|
-
},
|
|
81
|
-
async indexGet(key, id) {
|
|
82
|
-
const data = indices.get(key) || [];
|
|
83
|
-
const entry = data.find((item) => item.id === id);
|
|
84
|
-
if (!entry) return null;
|
|
85
|
-
return {
|
|
86
|
-
id: entry.id,
|
|
87
|
-
score: entry.score,
|
|
88
|
-
metadata: entry.metadata
|
|
89
|
-
};
|
|
90
|
-
},
|
|
91
|
-
async indexUpdate(key, id, metadata) {
|
|
92
|
-
const data = indices.get(key) || [];
|
|
93
|
-
const entryIndex = data.findIndex((item) => item.id === id);
|
|
94
|
-
if (entryIndex === -1) {
|
|
95
|
-
data.push({ id, score: Date.now(), metadata: { ...metadata, version: 1 } });
|
|
96
|
-
indices.set(key, data);
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
const entry = data[entryIndex];
|
|
100
|
-
const currentVersion = entry.metadata?.version || 0;
|
|
101
|
-
const expectedVersion = metadata.version !== void 0 ? metadata.version - 1 : currentVersion;
|
|
102
|
-
if (currentVersion !== expectedVersion) {
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
entry.metadata = {
|
|
106
|
-
...entry.metadata,
|
|
107
|
-
...metadata,
|
|
108
|
-
version: currentVersion + 1
|
|
109
|
-
};
|
|
110
|
-
indices.set(key, data);
|
|
111
|
-
return true;
|
|
112
|
-
},
|
|
113
|
-
async indexUpdateWithRetry(key, id, metadata, maxRetries = 3) {
|
|
114
|
-
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
115
|
-
const success = await this.indexUpdate(key, id, metadata);
|
|
116
|
-
if (success) return;
|
|
117
|
-
await new Promise((resolve) => setTimeout(resolve, 10 * Math.pow(2, attempt)));
|
|
118
|
-
}
|
|
119
|
-
throw new Error(`Failed to update index after ${maxRetries} retries`);
|
|
120
|
-
},
|
|
121
|
-
async indexIncrement(key, id, field, increment = 1) {
|
|
122
|
-
const data = indices.get(key) || [];
|
|
123
|
-
const entryIndex = data.findIndex((item) => item.id === id);
|
|
124
|
-
if (entryIndex === -1) {
|
|
125
|
-
const newEntry = {
|
|
126
|
-
id,
|
|
127
|
-
score: Date.now(),
|
|
128
|
-
metadata: { [field]: increment, version: 1 }
|
|
129
|
-
};
|
|
130
|
-
data.push(newEntry);
|
|
131
|
-
indices.set(key, data);
|
|
132
|
-
return increment;
|
|
133
|
-
}
|
|
134
|
-
const entry = data[entryIndex];
|
|
135
|
-
if (!entry.metadata) {
|
|
136
|
-
entry.metadata = { version: 0 };
|
|
137
|
-
}
|
|
138
|
-
const currentValue = entry.metadata[field] || 0;
|
|
139
|
-
const newValue = currentValue + increment;
|
|
140
|
-
entry.metadata[field] = newValue;
|
|
141
|
-
entry.metadata.version = (entry.metadata.version || 0) + 1;
|
|
142
|
-
indices.set(key, data);
|
|
143
|
-
return newValue;
|
|
144
|
-
},
|
|
145
|
-
async deleteStream(subject) {
|
|
146
|
-
events.delete(subject);
|
|
147
|
-
listeners.delete(subject);
|
|
148
|
-
},
|
|
149
|
-
async deleteByPattern(pattern) {
|
|
150
|
-
const regexPattern = pattern.replace(/\*/g, ".*").replace(/\?/g, ".");
|
|
151
|
-
const regex = new RegExp(`^${regexPattern}$`);
|
|
152
|
-
let count = 0;
|
|
153
|
-
for (const key of events.keys()) {
|
|
154
|
-
if (regex.test(key)) {
|
|
155
|
-
events.delete(key);
|
|
156
|
-
listeners.delete(key);
|
|
157
|
-
count++;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return count;
|
|
161
|
-
},
|
|
162
|
-
async deleteIndex(key) {
|
|
163
|
-
indices.delete(key);
|
|
164
|
-
},
|
|
165
|
-
async close() {
|
|
166
|
-
listeners.clear();
|
|
167
|
-
events.clear();
|
|
168
|
-
indices.clear();
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
}
|
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
import { useRuntimeConfig, useNventLogger } from "#imports";
|
|
2
|
-
import IORedis from "ioredis";
|
|
3
|
-
import { RedisPubSubGateway } from "./redisPubSubGateway.js";
|
|
4
|
-
function nowIso() {
|
|
5
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
6
|
-
}
|
|
7
|
-
export function createRedisAdapter() {
|
|
8
|
-
const rc = useRuntimeConfig();
|
|
9
|
-
const logger = useNventLogger("redis-adapter");
|
|
10
|
-
const conn = rc?.queue?.eventStore?.redis || {};
|
|
11
|
-
const rsOpts = rc?.queue?.eventStore?.options?.redisStreams || {};
|
|
12
|
-
const redis = new IORedis({
|
|
13
|
-
host: conn.host,
|
|
14
|
-
port: conn.port,
|
|
15
|
-
username: conn.username,
|
|
16
|
-
password: conn.password,
|
|
17
|
-
lazyConnect: true,
|
|
18
|
-
enableReadyCheck: false
|
|
19
|
-
// Disable ready check to avoid INFO command conflicts
|
|
20
|
-
});
|
|
21
|
-
const subscriber = new IORedis({
|
|
22
|
-
host: conn.host,
|
|
23
|
-
port: conn.port,
|
|
24
|
-
username: conn.username,
|
|
25
|
-
password: conn.password,
|
|
26
|
-
lazyConnect: true,
|
|
27
|
-
enableReadyCheck: false
|
|
28
|
-
});
|
|
29
|
-
const gateway = new RedisPubSubGateway(subscriber);
|
|
30
|
-
function buildFields(e) {
|
|
31
|
-
const dataStr = e.data !== void 0 ? JSON.stringify(e.data) : "";
|
|
32
|
-
const fields = [
|
|
33
|
-
"type",
|
|
34
|
-
String(e.type || ""),
|
|
35
|
-
"runId",
|
|
36
|
-
String(e.runId || ""),
|
|
37
|
-
"flowName",
|
|
38
|
-
String(e.flowName || ""),
|
|
39
|
-
"data",
|
|
40
|
-
dataStr,
|
|
41
|
-
"ts",
|
|
42
|
-
e.ts || nowIso()
|
|
43
|
-
];
|
|
44
|
-
if (e.stepName) {
|
|
45
|
-
fields.push("stepName", String(e.stepName));
|
|
46
|
-
}
|
|
47
|
-
if (e.stepId) {
|
|
48
|
-
fields.push("stepId", String(e.stepId));
|
|
49
|
-
}
|
|
50
|
-
if (e.attempt !== void 0) {
|
|
51
|
-
fields.push("attempt", String(e.attempt));
|
|
52
|
-
}
|
|
53
|
-
return fields;
|
|
54
|
-
}
|
|
55
|
-
function parseFieldsToRecord(id, arr) {
|
|
56
|
-
const obj = {};
|
|
57
|
-
for (let i = 0; i < arr.length; i += 2) {
|
|
58
|
-
const k = String(arr[i]);
|
|
59
|
-
const v = String(arr[i + 1] ?? "");
|
|
60
|
-
obj[k] = v;
|
|
61
|
-
}
|
|
62
|
-
let data;
|
|
63
|
-
try {
|
|
64
|
-
data = obj.data ? JSON.parse(obj.data) : void 0;
|
|
65
|
-
} catch {
|
|
66
|
-
data = void 0;
|
|
67
|
-
}
|
|
68
|
-
const rec = {
|
|
69
|
-
id,
|
|
70
|
-
ts: obj.ts || nowIso(),
|
|
71
|
-
type: obj.type || "event",
|
|
72
|
-
runId: obj.runId || "",
|
|
73
|
-
flowName: obj.flowName || "",
|
|
74
|
-
data
|
|
75
|
-
};
|
|
76
|
-
if (obj.stepName) rec.stepName = obj.stepName;
|
|
77
|
-
if (obj.stepId) rec.stepId = obj.stepId;
|
|
78
|
-
if (obj.attempt) rec.attempt = Number.parseInt(obj.attempt, 10);
|
|
79
|
-
return rec;
|
|
80
|
-
}
|
|
81
|
-
return {
|
|
82
|
-
async append(subject, e) {
|
|
83
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
84
|
-
const ts = nowIso();
|
|
85
|
-
const payloadFields = buildFields({ ...e, ts });
|
|
86
|
-
const stream = subject;
|
|
87
|
-
let id;
|
|
88
|
-
if (rsOpts?.trim?.maxLen && rsOpts.trim.maxLen > 0) {
|
|
89
|
-
const approx = rsOpts?.trim?.approx !== false;
|
|
90
|
-
const args = approx ? ["MAXLEN", "~", String(rsOpts.trim.maxLen)] : ["MAXLEN", String(rsOpts.trim.maxLen)];
|
|
91
|
-
id = await redis.xadd(stream, ...args, "*", ...payloadFields);
|
|
92
|
-
} else {
|
|
93
|
-
id = await redis.xadd(stream, "*", ...payloadFields);
|
|
94
|
-
}
|
|
95
|
-
const channel = `nq:events:${subject}`;
|
|
96
|
-
await redis.publish(channel, id);
|
|
97
|
-
if (process.env.NQ_DEBUG_EVENTS === "1") {
|
|
98
|
-
logger.info("[redis-streams] appended and published", { stream, id, channel, type: e.type });
|
|
99
|
-
}
|
|
100
|
-
const rec = { ...e, id, ts, subject };
|
|
101
|
-
return rec;
|
|
102
|
-
},
|
|
103
|
-
async read(subject, opts) {
|
|
104
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
105
|
-
const from = opts?.fromId ? opts.fromId : "0-0";
|
|
106
|
-
const count = opts?.limit || 100;
|
|
107
|
-
const dir = opts?.direction || "forward";
|
|
108
|
-
const stream = subject;
|
|
109
|
-
let resp = [];
|
|
110
|
-
if (dir === "backward") {
|
|
111
|
-
resp = await redis.xrevrange(stream, from === "0-0" ? "+" : `(${from}`, "-", "COUNT", count);
|
|
112
|
-
} else {
|
|
113
|
-
resp = await redis.xrange(stream, from === "0-0" ? "-" : `(${from}`, "+", "COUNT", count);
|
|
114
|
-
}
|
|
115
|
-
const out = [];
|
|
116
|
-
for (const [id, arr] of resp) {
|
|
117
|
-
try {
|
|
118
|
-
const rec = parseFieldsToRecord(id, arr);
|
|
119
|
-
out.push(rec);
|
|
120
|
-
} catch {
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return out;
|
|
124
|
-
},
|
|
125
|
-
async subscribe(subject, onEvent) {
|
|
126
|
-
const stream = subject;
|
|
127
|
-
const channel = `nq:events:${subject}`;
|
|
128
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
129
|
-
let running = true;
|
|
130
|
-
if (process.env.NQ_DEBUG_EVENTS === "1") {
|
|
131
|
-
logger.info("[redis-streams] subscribing", { stream, channel });
|
|
132
|
-
}
|
|
133
|
-
const messageHandler = async (messageId) => {
|
|
134
|
-
if (!running) return;
|
|
135
|
-
try {
|
|
136
|
-
const entries = await redis.xrange(stream, messageId, messageId, "COUNT", 1);
|
|
137
|
-
if (entries && entries.length > 0) {
|
|
138
|
-
const [id, arr] = entries[0];
|
|
139
|
-
const rec = parseFieldsToRecord(id, arr);
|
|
140
|
-
if (process.env.NQ_DEBUG_EVENTS === "1") {
|
|
141
|
-
logger.info("[redis-streams] received event", { stream, id, type: rec.type });
|
|
142
|
-
}
|
|
143
|
-
onEvent(rec);
|
|
144
|
-
}
|
|
145
|
-
} catch (err) {
|
|
146
|
-
if (process.env.NQ_DEBUG_EVENTS === "1") {
|
|
147
|
-
logger.error("[redis-streams] message handling error:", err);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
const unsubscribe = await gateway.subscribe(channel, messageHandler);
|
|
152
|
-
return {
|
|
153
|
-
unsubscribe() {
|
|
154
|
-
running = false;
|
|
155
|
-
unsubscribe();
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
},
|
|
159
|
-
async indexAdd(key, id, score, metadata) {
|
|
160
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
161
|
-
await redis.zadd(key, score, id);
|
|
162
|
-
if (metadata) {
|
|
163
|
-
const metaKey = `${key}:meta:${id}`;
|
|
164
|
-
const toStore = { version: "0" };
|
|
165
|
-
for (const [k, v] of Object.entries(metadata)) {
|
|
166
|
-
toStore[k] = Array.isArray(v) ? JSON.stringify(v) : String(v);
|
|
167
|
-
}
|
|
168
|
-
await redis.hset(metaKey, toStore);
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
async indexRead(key, opts) {
|
|
172
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
173
|
-
const offset = opts?.offset || 0;
|
|
174
|
-
const limit = opts?.limit || 50;
|
|
175
|
-
const end = offset + limit - 1;
|
|
176
|
-
const results = await redis.zrevrange(key, offset, end, "WITHSCORES");
|
|
177
|
-
const entries = [];
|
|
178
|
-
for (let i = 0; i < results.length; i += 2) {
|
|
179
|
-
const id = results[i];
|
|
180
|
-
const score = Number.parseInt(results[i + 1]);
|
|
181
|
-
const metaKey = `${key}:meta:${id}`;
|
|
182
|
-
const metadata = await redis.hgetall(metaKey);
|
|
183
|
-
let parsedMetadata = void 0;
|
|
184
|
-
if (Object.keys(metadata).length > 0) {
|
|
185
|
-
parsedMetadata = { ...metadata };
|
|
186
|
-
if (parsedMetadata.emittedEvents) {
|
|
187
|
-
parsedMetadata.emittedEvents = JSON.parse(parsedMetadata.emittedEvents);
|
|
188
|
-
}
|
|
189
|
-
if (parsedMetadata.version !== void 0) {
|
|
190
|
-
parsedMetadata.version = Number.parseInt(parsedMetadata.version, 10);
|
|
191
|
-
}
|
|
192
|
-
if (parsedMetadata.startedAt !== void 0) {
|
|
193
|
-
parsedMetadata.startedAt = Number.parseInt(parsedMetadata.startedAt, 10);
|
|
194
|
-
}
|
|
195
|
-
if (parsedMetadata.completedAt !== void 0) {
|
|
196
|
-
parsedMetadata.completedAt = Number.parseInt(parsedMetadata.completedAt, 10);
|
|
197
|
-
}
|
|
198
|
-
if (parsedMetadata.stepCount !== void 0) {
|
|
199
|
-
parsedMetadata.stepCount = Number.parseInt(parsedMetadata.stepCount, 10);
|
|
200
|
-
}
|
|
201
|
-
if (parsedMetadata.completedSteps !== void 0) {
|
|
202
|
-
parsedMetadata.completedSteps = Number.parseInt(parsedMetadata.completedSteps, 10);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
entries.push({
|
|
206
|
-
id,
|
|
207
|
-
score,
|
|
208
|
-
metadata: parsedMetadata
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
return entries;
|
|
212
|
-
},
|
|
213
|
-
async indexGet(key, id) {
|
|
214
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
215
|
-
const score = await redis.zscore(key, id);
|
|
216
|
-
if (!score) return null;
|
|
217
|
-
const metaKey = `${key}:meta:${id}`;
|
|
218
|
-
const metadata = await redis.hgetall(metaKey);
|
|
219
|
-
if (Object.keys(metadata).length === 0) {
|
|
220
|
-
return { id, score: Number.parseFloat(score) };
|
|
221
|
-
}
|
|
222
|
-
const parsed = { ...metadata };
|
|
223
|
-
if (parsed.emittedEvents) {
|
|
224
|
-
parsed.emittedEvents = JSON.parse(parsed.emittedEvents);
|
|
225
|
-
}
|
|
226
|
-
if (parsed.version !== void 0) {
|
|
227
|
-
parsed.version = Number.parseInt(parsed.version, 10);
|
|
228
|
-
}
|
|
229
|
-
if (parsed.startedAt !== void 0) {
|
|
230
|
-
parsed.startedAt = Number.parseInt(parsed.startedAt, 10);
|
|
231
|
-
}
|
|
232
|
-
if (parsed.completedAt !== void 0) {
|
|
233
|
-
parsed.completedAt = Number.parseInt(parsed.completedAt, 10);
|
|
234
|
-
}
|
|
235
|
-
if (parsed.stepCount !== void 0) {
|
|
236
|
-
parsed.stepCount = Number.parseInt(parsed.stepCount, 10);
|
|
237
|
-
}
|
|
238
|
-
if (parsed.completedSteps !== void 0) {
|
|
239
|
-
parsed.completedSteps = Number.parseInt(parsed.completedSteps, 10);
|
|
240
|
-
}
|
|
241
|
-
return {
|
|
242
|
-
id,
|
|
243
|
-
score: Number.parseFloat(score),
|
|
244
|
-
metadata: parsed
|
|
245
|
-
};
|
|
246
|
-
},
|
|
247
|
-
async indexUpdate(key, id, metadata) {
|
|
248
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
249
|
-
const metaKey = `${key}:meta:${id}`;
|
|
250
|
-
const current = await redis.hget(metaKey, "version");
|
|
251
|
-
const currentVersion = current ? Number.parseInt(current, 10) : 0;
|
|
252
|
-
const script = `
|
|
253
|
-
local current = redis.call('HGET', KEYS[1], 'version')
|
|
254
|
-
if current == ARGV[1] then
|
|
255
|
-
for i = 2, #ARGV, 2 do
|
|
256
|
-
redis.call('HSET', KEYS[1], ARGV[i], ARGV[i + 1])
|
|
257
|
-
end
|
|
258
|
-
redis.call('HSET', KEYS[1], 'version', tonumber(ARGV[1]) + 1)
|
|
259
|
-
return 1
|
|
260
|
-
else
|
|
261
|
-
return 0
|
|
262
|
-
end
|
|
263
|
-
`;
|
|
264
|
-
const args = [currentVersion.toString()];
|
|
265
|
-
for (const [k, v] of Object.entries(metadata)) {
|
|
266
|
-
if (v === void 0) continue;
|
|
267
|
-
args.push(k);
|
|
268
|
-
if (Array.isArray(v)) {
|
|
269
|
-
args.push(JSON.stringify(v.filter((item) => item != null)));
|
|
270
|
-
} else {
|
|
271
|
-
args.push(String(v));
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
const result = await redis.eval(script, 1, metaKey, ...args);
|
|
275
|
-
return result === 1;
|
|
276
|
-
},
|
|
277
|
-
async indexUpdateWithRetry(key, id, metadata, maxRetries = 3) {
|
|
278
|
-
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
279
|
-
const success = await this.indexUpdate(key, id, metadata);
|
|
280
|
-
if (success) return;
|
|
281
|
-
await new Promise((resolve) => setTimeout(resolve, 10 * Math.pow(2, attempt)));
|
|
282
|
-
}
|
|
283
|
-
throw new Error(`Failed to update index after ${maxRetries} retries`);
|
|
284
|
-
},
|
|
285
|
-
async indexIncrement(key, id, field, increment = 1) {
|
|
286
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
287
|
-
const metaKey = `${key}:meta:${id}`;
|
|
288
|
-
const newValue = await redis.hincrby(metaKey, field, increment);
|
|
289
|
-
await redis.hincrby(metaKey, "version", 1);
|
|
290
|
-
return newValue;
|
|
291
|
-
},
|
|
292
|
-
async setMetadataTTL(flowName, runId, ttlSeconds) {
|
|
293
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
294
|
-
const metaKey = `nq:flow:idx:${flowName}:meta:${runId}`;
|
|
295
|
-
await redis.expire(metaKey, ttlSeconds);
|
|
296
|
-
},
|
|
297
|
-
async cleanupCompletedFlows(key, retentionSeconds) {
|
|
298
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
299
|
-
const now = Date.now();
|
|
300
|
-
const cutoffTime = now - retentionSeconds * 1e3;
|
|
301
|
-
const oldEntries = await redis.zrangebyscore(key, "-inf", cutoffTime);
|
|
302
|
-
let removedCount = 0;
|
|
303
|
-
for (const runId of oldEntries) {
|
|
304
|
-
const metaKey = `${key}:meta:${runId}`;
|
|
305
|
-
const metadata = await redis.hgetall(metaKey);
|
|
306
|
-
if (metadata && (metadata.status === "completed" || metadata.status === "failed")) {
|
|
307
|
-
await redis.zrem(key, runId);
|
|
308
|
-
await redis.del(metaKey);
|
|
309
|
-
removedCount++;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
return removedCount;
|
|
313
|
-
},
|
|
314
|
-
async deleteStream(subject) {
|
|
315
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
316
|
-
await redis.del(subject);
|
|
317
|
-
},
|
|
318
|
-
async deleteByPattern(pattern) {
|
|
319
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
320
|
-
let cursor = "0";
|
|
321
|
-
const keysToDelete = [];
|
|
322
|
-
do {
|
|
323
|
-
const result = await redis.scan(cursor, "MATCH", pattern, "COUNT", 100);
|
|
324
|
-
cursor = result[0];
|
|
325
|
-
const keys = result[1];
|
|
326
|
-
if (keys.length > 0) {
|
|
327
|
-
keysToDelete.push(...keys);
|
|
328
|
-
}
|
|
329
|
-
} while (cursor !== "0");
|
|
330
|
-
if (keysToDelete.length > 0) {
|
|
331
|
-
await redis.del(...keysToDelete);
|
|
332
|
-
}
|
|
333
|
-
return keysToDelete.length;
|
|
334
|
-
},
|
|
335
|
-
async deleteIndex(key) {
|
|
336
|
-
if (!redis.status || redis.status === "end") await redis.connect();
|
|
337
|
-
await redis.del(key);
|
|
338
|
-
},
|
|
339
|
-
async close() {
|
|
340
|
-
try {
|
|
341
|
-
await gateway.cleanup();
|
|
342
|
-
await redis.quit();
|
|
343
|
-
await subscriber.quit();
|
|
344
|
-
} catch {
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type IORedis from 'ioredis';
|
|
2
|
-
/**
|
|
3
|
-
* Gateway pattern for Redis Pub/Sub
|
|
4
|
-
* Maintains a single 'message' listener and routes to channel-specific handlers
|
|
5
|
-
*/
|
|
6
|
-
export declare class RedisPubSubGateway {
|
|
7
|
-
private subscriber;
|
|
8
|
-
private channelSubscribers;
|
|
9
|
-
private initialized;
|
|
10
|
-
private logger;
|
|
11
|
-
constructor(subscriber: IORedis);
|
|
12
|
-
private initialize;
|
|
13
|
-
/**
|
|
14
|
-
* Subscribe to a channel with a handler
|
|
15
|
-
* Returns unsubscribe function
|
|
16
|
-
*/
|
|
17
|
-
subscribe(channel: string, handler: (messageId: string) => void): Promise<() => void>;
|
|
18
|
-
/**
|
|
19
|
-
* Get subscriber count for a channel (for debugging)
|
|
20
|
-
*/
|
|
21
|
-
getSubscriberCount(channel: string): number;
|
|
22
|
-
/**
|
|
23
|
-
* Get total subscriber count across all channels
|
|
24
|
-
*/
|
|
25
|
-
getTotalSubscriberCount(): number;
|
|
26
|
-
/**
|
|
27
|
-
* Cleanup all subscriptions
|
|
28
|
-
*/
|
|
29
|
-
cleanup(): Promise<void>;
|
|
30
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { useNventLogger } from "#imports";
|
|
2
|
-
export class RedisPubSubGateway {
|
|
3
|
-
constructor(subscriber) {
|
|
4
|
-
this.subscriber = subscriber;
|
|
5
|
-
}
|
|
6
|
-
channelSubscribers = /* @__PURE__ */ new Map();
|
|
7
|
-
initialized = false;
|
|
8
|
-
logger = useNventLogger("redis-pubsub-gateway");
|
|
9
|
-
initialize() {
|
|
10
|
-
if (this.initialized) return;
|
|
11
|
-
this.initialized = true;
|
|
12
|
-
this.subscriber.on("message", (channel, messageId) => {
|
|
13
|
-
const handlers = this.channelSubscribers.get(channel);
|
|
14
|
-
if (!handlers || handlers.size === 0) return;
|
|
15
|
-
for (const handler of handlers) {
|
|
16
|
-
try {
|
|
17
|
-
handler(messageId);
|
|
18
|
-
} catch (err) {
|
|
19
|
-
if (process.env.NQ_DEBUG_EVENTS === "1") {
|
|
20
|
-
this.logger.error("[redis-pubsub-gateway] Handler error:", err);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Subscribe to a channel with a handler
|
|
28
|
-
* Returns unsubscribe function
|
|
29
|
-
*/
|
|
30
|
-
async subscribe(channel, handler) {
|
|
31
|
-
this.initialize();
|
|
32
|
-
if (!this.channelSubscribers.has(channel)) {
|
|
33
|
-
this.channelSubscribers.set(channel, /* @__PURE__ */ new Set());
|
|
34
|
-
await this.subscriber.subscribe(channel);
|
|
35
|
-
if (process.env.NQ_DEBUG_EVENTS === "1") {
|
|
36
|
-
this.logger.info("[redis-pubsub-gateway] Subscribed to channel:", channel);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
this.channelSubscribers.get(channel).add(handler);
|
|
40
|
-
return () => {
|
|
41
|
-
const handlers = this.channelSubscribers.get(channel);
|
|
42
|
-
if (handlers) {
|
|
43
|
-
handlers.delete(handler);
|
|
44
|
-
if (handlers.size === 0) {
|
|
45
|
-
this.channelSubscribers.delete(channel);
|
|
46
|
-
this.subscriber.unsubscribe(channel).catch(() => {
|
|
47
|
-
});
|
|
48
|
-
if (process.env.NQ_DEBUG_EVENTS === "1") {
|
|
49
|
-
this.logger.info("[redis-pubsub-gateway] Unsubscribed from channel:", channel);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Get subscriber count for a channel (for debugging)
|
|
57
|
-
*/
|
|
58
|
-
getSubscriberCount(channel) {
|
|
59
|
-
return this.channelSubscribers.get(channel)?.size ?? 0;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Get total subscriber count across all channels
|
|
63
|
-
*/
|
|
64
|
-
getTotalSubscriberCount() {
|
|
65
|
-
let count = 0;
|
|
66
|
-
for (const handlers of this.channelSubscribers.values()) {
|
|
67
|
-
count += handlers.size;
|
|
68
|
-
}
|
|
69
|
-
return count;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Cleanup all subscriptions
|
|
73
|
-
*/
|
|
74
|
-
async cleanup() {
|
|
75
|
-
const channels = Array.from(this.channelSubscribers.keys());
|
|
76
|
-
this.channelSubscribers.clear();
|
|
77
|
-
if (channels.length > 0) {
|
|
78
|
-
await this.subscriber.unsubscribe(...channels).catch(() => {
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { getStreamNames } from './streamNames.js';
|
|
2
|
-
import type { EventStoreAdapter } from './types.js';
|
|
3
|
-
export interface EventStoreInstance {
|
|
4
|
-
name: string;
|
|
5
|
-
append: EventStoreAdapter['append'];
|
|
6
|
-
read: EventStoreAdapter['read'];
|
|
7
|
-
subscribe: EventStoreAdapter['subscribe'];
|
|
8
|
-
}
|
|
9
|
-
export interface EventStoreFactory {
|
|
10
|
-
adapter: EventStoreAdapter;
|
|
11
|
-
names: ReturnType<typeof getStreamNames>;
|
|
12
|
-
stream(name: string): EventStoreInstance;
|
|
13
|
-
/** Idempotently start stream store wiring that persists ingress events and projections */
|
|
14
|
-
start(): void;
|
|
15
|
-
/** Stop wiring and release listeners */
|
|
16
|
-
stop(): void;
|
|
17
|
-
}
|
|
18
|
-
export declare function getEventStoreFactory(): EventStoreFactory;
|
|
19
|
-
export declare function setEventStoreFactory(f: EventStoreFactory): void;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { useRuntimeConfig, useNventLogger } from "#imports";
|
|
2
|
-
import { getStreamNames } from "./streamNames.js";
|
|
3
|
-
import { createRedisAdapter } from "./adapters/redis/redisAdapter.js";
|
|
4
|
-
import { createMemoryAdapter } from "./adapters/memoryAdapter.js";
|
|
5
|
-
import { createFileAdapter } from "./adapters/fileAdapter.js";
|
|
6
|
-
import { createWiringRegistry } from "./wiring/registry.js";
|
|
7
|
-
let cachedFactory = null;
|
|
8
|
-
export function getEventStoreFactory() {
|
|
9
|
-
if (cachedFactory) return cachedFactory;
|
|
10
|
-
const logger = useNventLogger("event-store-factory");
|
|
11
|
-
const rc = useRuntimeConfig();
|
|
12
|
-
const adapter = rc?.queue?.eventStore?.adapter || "memory";
|
|
13
|
-
let adapterInstance;
|
|
14
|
-
if (adapter === "memory") adapterInstance = createMemoryAdapter();
|
|
15
|
-
else if (adapter === "file") adapterInstance = createFileAdapter();
|
|
16
|
-
else if (adapter === "redis") adapterInstance = createRedisAdapter();
|
|
17
|
-
else adapterInstance = createMemoryAdapter();
|
|
18
|
-
logger.debug("Event store initialized", { adapter, adapterType: adapter });
|
|
19
|
-
const names = getStreamNames();
|
|
20
|
-
const wiring = createWiringRegistry({ adapter: adapterInstance, names });
|
|
21
|
-
const factory = {
|
|
22
|
-
adapter: adapterInstance,
|
|
23
|
-
names,
|
|
24
|
-
stream(name) {
|
|
25
|
-
return {
|
|
26
|
-
name,
|
|
27
|
-
append: (s, e) => adapterInstance.append(s, e),
|
|
28
|
-
read: (s, o) => adapterInstance.read(s, o),
|
|
29
|
-
subscribe: (s, cb) => adapterInstance.subscribe(s, cb)
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
|
-
start() {
|
|
33
|
-
wiring.start();
|
|
34
|
-
},
|
|
35
|
-
stop() {
|
|
36
|
-
wiring.stop();
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
cachedFactory = factory;
|
|
40
|
-
return factory;
|
|
41
|
-
}
|
|
42
|
-
export function setEventStoreFactory(f) {
|
|
43
|
-
cachedFactory = f;
|
|
44
|
-
}
|