nvent 0.5.4 → 0.5.5
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.json +1 -1
- package/dist/module.mjs +110 -24
- package/dist/runtime/adapters/factory.js +8 -7
- package/dist/runtime/adapters/interfaces/queue.d.ts +5 -0
- package/dist/runtime/config/index.js +14 -1
- package/dist/runtime/config/types.d.ts +42 -0
- package/dist/runtime/events/types.d.ts +0 -1
- package/dist/runtime/events/utils/stallDetector.d.ts +13 -77
- package/dist/runtime/events/utils/stallDetector.js +8 -192
- package/dist/runtime/events/wiring/flowWiring.js +311 -107
- package/dist/runtime/events/wiring/triggerWiring.js +3 -1
- package/dist/runtime/nitro/plugins/02.workers.js +31 -2
- package/dist/runtime/nitro/routes/webhook.await.js +28 -6
- package/dist/runtime/nitro/utils/awaitPatterns/event.js +58 -50
- package/dist/runtime/nitro/utils/awaitPatterns/schedule.js +6 -1
- package/dist/runtime/nitro/utils/awaitPatterns/time.d.ts +1 -1
- package/dist/runtime/nitro/utils/awaitPatterns/time.js +6 -2
- package/dist/runtime/nitro/utils/awaitPatterns/webhook.js +53 -45
- package/dist/runtime/nitro/utils/defineFunction.d.ts +2 -9
- package/dist/runtime/nitro/utils/defineFunction.js +1 -14
- package/dist/runtime/nitro/utils/defineFunctionConfig.d.ts +84 -16
- package/dist/runtime/nitro/utils/defineHooks.d.ts +64 -10
- package/dist/runtime/nitro/utils/defineHooks.js +3 -0
- package/dist/runtime/nitro/utils/useAwait.d.ts +12 -0
- package/dist/runtime/nitro/utils/useAwait.js +34 -4
- package/dist/runtime/nitro/utils/useFlow.js +13 -2
- package/dist/runtime/nitro/utils/useHookRegistry.d.ts +10 -4
- package/dist/runtime/scheduler/scheduler.d.ts +19 -0
- package/dist/runtime/scheduler/scheduler.js +184 -8
- package/dist/runtime/scheduler/types.d.ts +6 -0
- package/dist/runtime/worker/node/runner.js +32 -91
- package/dist/runtime/worker/system/awaitHandlers.d.ts +27 -0
- package/dist/runtime/worker/system/awaitHandlers.js +230 -0
- package/dist/runtime/worker/system/index.d.ts +24 -0
- package/dist/runtime/worker/system/index.js +39 -0
- package/package.json +1 -1
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { useAwait, useHookRegistry, useNventLogger, $useFunctionRegistry, useEventManager } from "#imports";
|
|
2
|
+
const logger = useNventLogger("system-await-handlers");
|
|
3
|
+
export async function awaitRegisterHandler(job) {
|
|
4
|
+
const { flowId, flowName, stepName, position, awaitConfig, input } = job.data;
|
|
5
|
+
logger.info("Handling await registration", {
|
|
6
|
+
flowId,
|
|
7
|
+
flowName,
|
|
8
|
+
stepName,
|
|
9
|
+
position,
|
|
10
|
+
awaitType: awaitConfig?.type
|
|
11
|
+
});
|
|
12
|
+
try {
|
|
13
|
+
const { register } = useAwait();
|
|
14
|
+
const awaitResult = await register(
|
|
15
|
+
flowId,
|
|
16
|
+
stepName,
|
|
17
|
+
flowName,
|
|
18
|
+
awaitConfig,
|
|
19
|
+
position
|
|
20
|
+
);
|
|
21
|
+
logger.info("Registered await pattern", {
|
|
22
|
+
flowId,
|
|
23
|
+
flowName,
|
|
24
|
+
stepName,
|
|
25
|
+
position
|
|
26
|
+
});
|
|
27
|
+
const hookRegistry = useHookRegistry();
|
|
28
|
+
const hooks = hookRegistry.load(flowName, stepName);
|
|
29
|
+
if (hooks?.onAwaitRegister) {
|
|
30
|
+
try {
|
|
31
|
+
let hookData = {};
|
|
32
|
+
if (awaitConfig.type === "webhook" && awaitResult.webhookUrl) {
|
|
33
|
+
hookData = { webhookUrl: awaitResult.webhookUrl };
|
|
34
|
+
} else if (awaitConfig.type === "event" && awaitResult.eventName) {
|
|
35
|
+
hookData = { eventName: awaitResult.eventName };
|
|
36
|
+
} else if (awaitConfig.type === "schedule" && awaitConfig.cron) {
|
|
37
|
+
hookData = {
|
|
38
|
+
cronExpression: awaitConfig.cron,
|
|
39
|
+
nextOccurrence: awaitResult.nextOccurrence || /* @__PURE__ */ new Date()
|
|
40
|
+
};
|
|
41
|
+
} else if (awaitConfig.type === "time" && awaitConfig.delay) {
|
|
42
|
+
hookData = { delayMs: awaitConfig.delay };
|
|
43
|
+
}
|
|
44
|
+
const eventManager = useEventManager();
|
|
45
|
+
const hookCtx = {
|
|
46
|
+
flowId,
|
|
47
|
+
flowName,
|
|
48
|
+
stepName,
|
|
49
|
+
awaitType: awaitConfig.type,
|
|
50
|
+
awaitConfig,
|
|
51
|
+
position,
|
|
52
|
+
logger: {
|
|
53
|
+
log: (level, msg, meta) => {
|
|
54
|
+
void eventManager.publishBus({
|
|
55
|
+
type: "log",
|
|
56
|
+
runId: flowId,
|
|
57
|
+
flowName,
|
|
58
|
+
stepName,
|
|
59
|
+
data: { level, message: msg, ...meta }
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
await hooks.onAwaitRegister(
|
|
65
|
+
hookData,
|
|
66
|
+
input || {},
|
|
67
|
+
hookCtx
|
|
68
|
+
);
|
|
69
|
+
logger.info("onAwaitRegister hook completed", {
|
|
70
|
+
flowId,
|
|
71
|
+
flowName,
|
|
72
|
+
stepName
|
|
73
|
+
});
|
|
74
|
+
} catch (err) {
|
|
75
|
+
logger.error("onAwaitRegister hook failed", {
|
|
76
|
+
flowId,
|
|
77
|
+
flowName,
|
|
78
|
+
stepName,
|
|
79
|
+
error: err.message
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return { success: true, awaitResult };
|
|
84
|
+
} catch (err) {
|
|
85
|
+
logger.error("Failed to register await", {
|
|
86
|
+
flowId,
|
|
87
|
+
flowName,
|
|
88
|
+
stepName,
|
|
89
|
+
error: err.message,
|
|
90
|
+
stack: err.stack
|
|
91
|
+
});
|
|
92
|
+
throw err;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export async function awaitResolveHandler(job) {
|
|
96
|
+
const { flowId, flowName, stepName, position, triggerData, input } = job.data;
|
|
97
|
+
logger.info("Handling await resolution", {
|
|
98
|
+
flowId,
|
|
99
|
+
flowName,
|
|
100
|
+
stepName,
|
|
101
|
+
position
|
|
102
|
+
});
|
|
103
|
+
try {
|
|
104
|
+
const hookRegistry = useHookRegistry();
|
|
105
|
+
const hooks = hookRegistry.load(flowName, stepName);
|
|
106
|
+
if (hooks?.onAwaitResolve) {
|
|
107
|
+
try {
|
|
108
|
+
const registry = $useFunctionRegistry();
|
|
109
|
+
const flowRegistry = (registry?.flows || {})[flowName];
|
|
110
|
+
const stepMeta = flowRegistry?.steps?.[stepName];
|
|
111
|
+
const awaitConfig = position === "before" ? stepMeta?.awaitBefore : stepMeta?.awaitAfter;
|
|
112
|
+
const eventManager = useEventManager();
|
|
113
|
+
const hookCtx = {
|
|
114
|
+
flowId,
|
|
115
|
+
flowName,
|
|
116
|
+
stepName,
|
|
117
|
+
awaitType: awaitConfig?.type || "unknown",
|
|
118
|
+
resolvedData: triggerData,
|
|
119
|
+
position,
|
|
120
|
+
logger: {
|
|
121
|
+
log: (level, msg, meta) => {
|
|
122
|
+
void eventManager.publishBus({
|
|
123
|
+
type: "log",
|
|
124
|
+
runId: flowId,
|
|
125
|
+
flowName,
|
|
126
|
+
stepName,
|
|
127
|
+
data: { level, message: msg, ...meta }
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
await hooks.onAwaitResolve(
|
|
133
|
+
triggerData || {},
|
|
134
|
+
input || {},
|
|
135
|
+
hookCtx
|
|
136
|
+
);
|
|
137
|
+
logger.info("onAwaitResolve hook completed", {
|
|
138
|
+
flowId,
|
|
139
|
+
flowName,
|
|
140
|
+
stepName
|
|
141
|
+
});
|
|
142
|
+
} catch (err) {
|
|
143
|
+
logger.error("onAwaitResolve hook failed", {
|
|
144
|
+
flowId,
|
|
145
|
+
flowName,
|
|
146
|
+
stepName,
|
|
147
|
+
error: err.message
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return { success: true };
|
|
152
|
+
} catch (err) {
|
|
153
|
+
logger.error("Failed to handle await resolution", {
|
|
154
|
+
flowId,
|
|
155
|
+
flowName,
|
|
156
|
+
stepName,
|
|
157
|
+
error: err.message,
|
|
158
|
+
stack: err.stack
|
|
159
|
+
});
|
|
160
|
+
throw err;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
export async function awaitTimeoutHandler(job) {
|
|
164
|
+
const { flowId, flowName, stepName, position, timeoutAction, input } = job.data;
|
|
165
|
+
logger.info("Handling await timeout", {
|
|
166
|
+
flowId,
|
|
167
|
+
flowName,
|
|
168
|
+
stepName,
|
|
169
|
+
position,
|
|
170
|
+
timeoutAction
|
|
171
|
+
});
|
|
172
|
+
try {
|
|
173
|
+
const hookRegistry = useHookRegistry();
|
|
174
|
+
const hooks = hookRegistry.load(flowName, stepName);
|
|
175
|
+
if (hooks?.onAwaitTimeout) {
|
|
176
|
+
try {
|
|
177
|
+
const registry = $useFunctionRegistry();
|
|
178
|
+
const flowRegistry = (registry?.flows || {})[flowName];
|
|
179
|
+
const stepMeta = flowRegistry?.steps?.[stepName];
|
|
180
|
+
const awaitConfig = position === "before" ? stepMeta?.awaitBefore : stepMeta?.awaitAfter;
|
|
181
|
+
const eventManager = useEventManager();
|
|
182
|
+
const hookCtx = {
|
|
183
|
+
flowId,
|
|
184
|
+
flowName,
|
|
185
|
+
stepName,
|
|
186
|
+
awaitType: awaitConfig?.type || "unknown",
|
|
187
|
+
timeoutAction: timeoutAction || "fail",
|
|
188
|
+
position,
|
|
189
|
+
logger: {
|
|
190
|
+
log: (level, msg, meta) => {
|
|
191
|
+
void eventManager.publishBus({
|
|
192
|
+
type: "log",
|
|
193
|
+
runId: flowId,
|
|
194
|
+
flowName,
|
|
195
|
+
stepName,
|
|
196
|
+
data: { level, message: msg, ...meta }
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
await hooks.onAwaitTimeout(
|
|
202
|
+
input || {},
|
|
203
|
+
hookCtx
|
|
204
|
+
);
|
|
205
|
+
logger.info("onAwaitTimeout hook completed", {
|
|
206
|
+
flowId,
|
|
207
|
+
flowName,
|
|
208
|
+
stepName
|
|
209
|
+
});
|
|
210
|
+
} catch (err) {
|
|
211
|
+
logger.error("onAwaitTimeout hook failed", {
|
|
212
|
+
flowId,
|
|
213
|
+
flowName,
|
|
214
|
+
stepName,
|
|
215
|
+
error: err.message
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return { success: true };
|
|
220
|
+
} catch (err) {
|
|
221
|
+
logger.error("Failed to handle await timeout", {
|
|
222
|
+
flowId,
|
|
223
|
+
flowName,
|
|
224
|
+
stepName,
|
|
225
|
+
error: err.message,
|
|
226
|
+
stack: err.stack
|
|
227
|
+
});
|
|
228
|
+
throw err;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* System handlers for await lifecycle events
|
|
3
|
+
* These handlers are registered on each queue that has workers with lifecycle hooks
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* System handler names
|
|
7
|
+
* These handlers run in the same queue as the step that has hooks
|
|
8
|
+
*/
|
|
9
|
+
export declare const SYSTEM_HANDLERS: {
|
|
10
|
+
readonly AWAIT_REGISTER: "__nvent_await_register";
|
|
11
|
+
readonly AWAIT_RESOLVE: "__nvent_await_resolve";
|
|
12
|
+
readonly AWAIT_TIMEOUT: "__nvent_await_timeout";
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Register system handlers on a specific queue
|
|
16
|
+
* Allows await lifecycle hooks to run in the same queue as the step
|
|
17
|
+
*/
|
|
18
|
+
export declare function registerSystemHandlersOnQueue(queueName: string, concurrency?: number): void;
|
|
19
|
+
/**
|
|
20
|
+
* Initialize system workers
|
|
21
|
+
* Registers internal handlers with the queue adapter
|
|
22
|
+
* @deprecated System handlers are now registered on each step's queue
|
|
23
|
+
*/
|
|
24
|
+
export declare function initializeSystemWorkers(): Promise<void>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useQueueAdapter, useRuntimeConfig, useNventLogger } from "#imports";
|
|
2
|
+
import { awaitRegisterHandler, awaitResolveHandler, awaitTimeoutHandler } from "./awaitHandlers.js";
|
|
3
|
+
const logger = useNventLogger("system-workers");
|
|
4
|
+
export const SYSTEM_HANDLERS = {
|
|
5
|
+
AWAIT_REGISTER: "__nvent_await_register",
|
|
6
|
+
AWAIT_RESOLVE: "__nvent_await_resolve",
|
|
7
|
+
AWAIT_TIMEOUT: "__nvent_await_timeout"
|
|
8
|
+
};
|
|
9
|
+
export function registerSystemHandlersOnQueue(queueName, concurrency) {
|
|
10
|
+
try {
|
|
11
|
+
const queue = useQueueAdapter();
|
|
12
|
+
const config = useRuntimeConfig();
|
|
13
|
+
const handlerConcurrency = concurrency || config?.nvent?.queue?.systemConcurrency || 5;
|
|
14
|
+
logger.debug("Registering system handlers on queue", {
|
|
15
|
+
queue: queueName,
|
|
16
|
+
concurrency: handlerConcurrency,
|
|
17
|
+
handlers: Object.values(SYSTEM_HANDLERS)
|
|
18
|
+
});
|
|
19
|
+
queue.registerWorker(queueName, SYSTEM_HANDLERS.AWAIT_REGISTER, awaitRegisterHandler, {
|
|
20
|
+
concurrency: handlerConcurrency
|
|
21
|
+
});
|
|
22
|
+
queue.registerWorker(queueName, SYSTEM_HANDLERS.AWAIT_RESOLVE, awaitResolveHandler, {
|
|
23
|
+
concurrency: handlerConcurrency
|
|
24
|
+
});
|
|
25
|
+
queue.registerWorker(queueName, SYSTEM_HANDLERS.AWAIT_TIMEOUT, awaitTimeoutHandler, {
|
|
26
|
+
concurrency: handlerConcurrency
|
|
27
|
+
});
|
|
28
|
+
} catch (err) {
|
|
29
|
+
logger.error("Failed to register system handlers on queue", {
|
|
30
|
+
queue: queueName,
|
|
31
|
+
error: err.message,
|
|
32
|
+
stack: err.stack
|
|
33
|
+
});
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export async function initializeSystemWorkers() {
|
|
38
|
+
logger.info("System workers module loaded (handlers registered per-queue)");
|
|
39
|
+
}
|