@versori/run 0.5.10 → 0.6.0-alpha.1
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/esm/src/connection/internal/CredentialHolder.js +1 -1
- package/esm/src/connection/internal/FetchBuilder.d.ts +9 -2
- package/esm/src/connection/internal/FetchBuilder.d.ts.map +1 -1
- package/esm/src/connection/internal/FetchBuilder.js +124 -3
- package/esm/src/context/Context.d.ts +5 -0
- package/esm/src/context/Context.d.ts.map +1 -1
- package/esm/src/context/Context.js +6 -1
- package/esm/src/context/VanillaContext.d.ts.map +1 -1
- package/esm/src/context/VanillaContext.js +0 -1
- package/esm/src/dsl/Workflow.d.ts.map +1 -1
- package/esm/src/dsl/Workflow.js +2 -0
- package/esm/src/dsl/http/types.d.ts +2 -0
- package/esm/src/dsl/http/types.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/configloader.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/configloader.js +1 -1
- package/esm/src/dsl/http/versori/cronapi.d.ts +2 -3
- package/esm/src/dsl/http/versori/cronapi.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/cronapi.js +14 -15
- package/esm/src/dsl/http/versori/kvapi/core/OpenAPI.js +1 -1
- package/esm/src/dsl/triggers/WebhookTrigger.d.ts.map +1 -1
- package/esm/src/dsl/triggers/WebhookTrigger.js +3 -1
- package/esm/src/internal/constants.d.ts +3 -0
- package/esm/src/internal/constants.d.ts.map +1 -1
- package/esm/src/internal/constants.js +3 -0
- package/esm/src/internal/supervisor.d.ts +23 -0
- package/esm/src/internal/supervisor.d.ts.map +1 -0
- package/esm/src/internal/supervisor.js +267 -0
- package/esm/src/interpreter/durable/DurableInterpreter.d.ts +9 -2
- package/esm/src/interpreter/durable/DurableInterpreter.d.ts.map +1 -1
- package/esm/src/interpreter/durable/DurableInterpreter.js +57 -13
- package/esm/src/interpreter/durable/ObservableCompiler.d.ts +6 -1
- package/esm/src/interpreter/durable/ObservableCompiler.d.ts.map +1 -1
- package/esm/src/interpreter/durable/Queue.js +1 -1
- package/esm/src/interpreter/durable/compilers/catch.d.ts.map +1 -1
- package/esm/src/interpreter/durable/compilers/catch.js +3 -1
- package/esm/src/interpreter/durable/compilers/fn.d.ts.map +1 -1
- package/esm/src/interpreter/durable/compilers/fn.js +29 -6
- package/esm/src/interpreter/durable/compilers/http.d.ts.map +1 -1
- package/esm/src/interpreter/durable/compilers/http.js +45 -11
- package/esm/src/interpreter/durable/compilers/schedule.d.ts.map +1 -1
- package/esm/src/interpreter/durable/compilers/schedule.js +4 -3
- package/esm/src/interpreter/durable/compilers/webhook.d.ts.map +1 -1
- package/esm/src/interpreter/durable/compilers/webhook.js +2 -0
- package/esm/src/interpreter/memory/MemoryInterpreter.d.ts +8 -1
- package/esm/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
- package/esm/src/interpreter/memory/MemoryInterpreter.js +56 -12
- package/esm/src/interpreter/memory/ObservableCompiler.d.ts +6 -1
- package/esm/src/interpreter/memory/ObservableCompiler.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/catch.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/catch.js +5 -0
- package/esm/src/interpreter/memory/compilers/fn.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/fn.js +29 -18
- package/esm/src/interpreter/memory/compilers/http.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/http.js +44 -10
- package/esm/src/interpreter/memory/compilers/schedule.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/schedule.js +61 -4
- package/esm/src/interpreter/memory/compilers/webhook.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/webhook.js +9 -3
- package/esm/src/interpreter/vanilla/VanillaInterpreter.d.ts +1 -0
- package/esm/src/interpreter/vanilla/VanillaInterpreter.d.ts.map +1 -1
- package/esm/src/interpreter/vanilla/VanillaInterpreter.js +30 -6
- package/esm/src/interpreter/vanilla/compilers/schedule.js +1 -1
- package/esm/src/issues/Issues.d.ts.map +1 -1
- package/esm/src/issues/Issues.js +6 -1
- package/esm/src/kv/KeyValue.d.ts +3 -7
- package/esm/src/kv/KeyValue.d.ts.map +1 -1
- package/esm/src/kv/memory/MemoryKeyValueProvider.d.ts +0 -4
- package/esm/src/kv/memory/MemoryKeyValueProvider.d.ts.map +1 -1
- package/esm/src/kv/memory/MemoryKeyValueProvider.js +0 -50
- package/esm/src/kv/nats/NatsKeyValueProvider.d.ts.map +1 -1
- package/esm/src/kv/nats/NatsKeyValueProvider.js +0 -14
- package/esm/src/kv/sdk/SDKKeyValueProvider.d.ts.map +1 -1
- package/esm/src/kv/sdk/SDKKeyValueProvider.js +0 -12
- package/esm/src/observability/logging/ConsoleLogger.d.ts.map +1 -1
- package/package.json +3 -1
- package/script/src/connection/internal/CredentialHolder.js +1 -1
- package/script/src/connection/internal/FetchBuilder.d.ts +9 -2
- package/script/src/connection/internal/FetchBuilder.d.ts.map +1 -1
- package/script/src/connection/internal/FetchBuilder.js +147 -3
- package/script/src/context/Context.d.ts +5 -0
- package/script/src/context/Context.d.ts.map +1 -1
- package/script/src/context/Context.js +6 -1
- package/script/src/context/VanillaContext.d.ts.map +1 -1
- package/script/src/context/VanillaContext.js +0 -1
- package/script/src/dsl/Workflow.d.ts.map +1 -1
- package/script/src/dsl/Workflow.js +2 -0
- package/script/src/dsl/http/types.d.ts +2 -0
- package/script/src/dsl/http/types.d.ts.map +1 -1
- package/script/src/dsl/http/versori/configloader.d.ts.map +1 -1
- package/script/src/dsl/http/versori/configloader.js +1 -1
- package/script/src/dsl/http/versori/cronapi.d.ts +2 -3
- package/script/src/dsl/http/versori/cronapi.d.ts.map +1 -1
- package/script/src/dsl/http/versori/cronapi.js +14 -15
- package/script/src/dsl/http/versori/kvapi/core/OpenAPI.js +1 -1
- package/script/src/dsl/triggers/WebhookTrigger.d.ts.map +1 -1
- package/script/src/dsl/triggers/WebhookTrigger.js +3 -1
- package/script/src/internal/constants.d.ts +3 -0
- package/script/src/internal/constants.d.ts.map +1 -1
- package/script/src/internal/constants.js +4 -1
- package/script/src/internal/supervisor.d.ts +23 -0
- package/script/src/internal/supervisor.d.ts.map +1 -0
- package/script/src/internal/supervisor.js +275 -0
- package/script/src/interpreter/durable/DurableInterpreter.d.ts +9 -2
- package/script/src/interpreter/durable/DurableInterpreter.d.ts.map +1 -1
- package/script/src/interpreter/durable/DurableInterpreter.js +62 -18
- package/script/src/interpreter/durable/ObservableCompiler.d.ts +6 -1
- package/script/src/interpreter/durable/ObservableCompiler.d.ts.map +1 -1
- package/script/src/interpreter/durable/Queue.js +1 -1
- package/script/src/interpreter/durable/compilers/catch.d.ts.map +1 -1
- package/script/src/interpreter/durable/compilers/catch.js +3 -1
- package/script/src/interpreter/durable/compilers/fn.d.ts.map +1 -1
- package/script/src/interpreter/durable/compilers/fn.js +28 -5
- package/script/src/interpreter/durable/compilers/http.d.ts.map +1 -1
- package/script/src/interpreter/durable/compilers/http.js +45 -11
- package/script/src/interpreter/durable/compilers/schedule.d.ts.map +1 -1
- package/script/src/interpreter/durable/compilers/schedule.js +4 -3
- package/script/src/interpreter/durable/compilers/webhook.d.ts.map +1 -1
- package/script/src/interpreter/durable/compilers/webhook.js +2 -0
- package/script/src/interpreter/memory/MemoryInterpreter.d.ts +8 -1
- package/script/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
- package/script/src/interpreter/memory/MemoryInterpreter.js +55 -11
- package/script/src/interpreter/memory/ObservableCompiler.d.ts +6 -1
- package/script/src/interpreter/memory/ObservableCompiler.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/catch.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/catch.js +5 -0
- package/script/src/interpreter/memory/compilers/fn.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/fn.js +28 -17
- package/script/src/interpreter/memory/compilers/http.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/http.js +44 -10
- package/script/src/interpreter/memory/compilers/schedule.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/schedule.js +61 -4
- package/script/src/interpreter/memory/compilers/webhook.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/webhook.js +9 -3
- package/script/src/interpreter/vanilla/VanillaInterpreter.d.ts +1 -0
- package/script/src/interpreter/vanilla/VanillaInterpreter.d.ts.map +1 -1
- package/script/src/interpreter/vanilla/VanillaInterpreter.js +30 -6
- package/script/src/interpreter/vanilla/compilers/schedule.js +1 -1
- package/script/src/issues/Issues.d.ts.map +1 -1
- package/script/src/issues/Issues.js +6 -1
- package/script/src/kv/KeyValue.d.ts +3 -7
- package/script/src/kv/KeyValue.d.ts.map +1 -1
- package/script/src/kv/memory/MemoryKeyValueProvider.d.ts +0 -4
- package/script/src/kv/memory/MemoryKeyValueProvider.d.ts.map +1 -1
- package/script/src/kv/memory/MemoryKeyValueProvider.js +0 -50
- package/script/src/kv/nats/NatsKeyValueProvider.d.ts.map +1 -1
- package/script/src/kv/nats/NatsKeyValueProvider.js +0 -14
- package/script/src/kv/sdk/SDKKeyValueProvider.d.ts.map +1 -1
- package/script/src/kv/sdk/SDKKeyValueProvider.js +0 -12
- package/script/src/observability/logging/ConsoleLogger.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/constants.d.ts +0 -21
- package/esm/src/dsl/http/versori/constants.d.ts.map +0 -1
- package/esm/src/dsl/http/versori/constants.js +0 -38
- package/esm/src/kv/fingerprintExternalUserId.d.ts +0 -6
- package/esm/src/kv/fingerprintExternalUserId.d.ts.map +0 -1
- package/esm/src/kv/fingerprintExternalUserId.js +0 -20
- package/script/src/dsl/http/versori/constants.d.ts +0 -21
- package/script/src/dsl/http/versori/constants.d.ts.map +0 -1
- package/script/src/dsl/http/versori/constants.js +0 -41
- package/script/src/kv/fingerprintExternalUserId.d.ts +0 -6
- package/script/src/kv/fingerprintExternalUserId.d.ts.map +0 -1
- package/script/src/kv/fingerprintExternalUserId.js +0 -23
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Versori Group Inc
|
|
4
|
+
*
|
|
5
|
+
* Use of this software is governed by the Business Source License 1.1
|
|
6
|
+
* included in the LICENSE file at the root of this repository.
|
|
7
|
+
*
|
|
8
|
+
* Change Date: 2029-01-01
|
|
9
|
+
* Change License: Apache License, Version 2.0
|
|
10
|
+
*
|
|
11
|
+
* As of the Change Date, in accordance with the Business Source License,
|
|
12
|
+
* use of this software will be governed by the Apache License, Version 2.0.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Fake = exports.enabled = void 0;
|
|
16
|
+
exports.signalReady = signalReady;
|
|
17
|
+
exports.registerWorkflow = registerWorkflow;
|
|
18
|
+
exports.sendTaskStartEvent = sendTaskStartEvent;
|
|
19
|
+
exports.mockAPIRequest = mockAPIRequest;
|
|
20
|
+
const core_1 = require("@opentelemetry/core");
|
|
21
|
+
const ConsoleLogger_js_1 = require("../observability/logging/ConsoleLogger.js");
|
|
22
|
+
const ChainTask_js_1 = require("../dsl/tasks/ChainTask.js");
|
|
23
|
+
const ScheduleTrigger_js_1 = require("../dsl/triggers/ScheduleTrigger.js");
|
|
24
|
+
const WebhookTrigger_js_1 = require("../dsl/triggers/WebhookTrigger.js");
|
|
25
|
+
const DurableTrigger_js_1 = require("../dsl/triggers/DurableTrigger.js");
|
|
26
|
+
const Task_js_1 = require("../dsl/Task.js");
|
|
27
|
+
const CatchTask_js_1 = require("../dsl/tasks/CatchTask.js");
|
|
28
|
+
const FnTask_js_1 = require("../dsl/tasks/FnTask.js");
|
|
29
|
+
const HttpTask_js_1 = require("../dsl/tasks/HttpTask.js");
|
|
30
|
+
const BackgroundTask_js_1 = require("../dsl/tasks/BackgroundTask.js");
|
|
31
|
+
const ParallelTask_js_1 = require("../dsl/tasks/ParallelTask.js");
|
|
32
|
+
const supervisorURL = (function () {
|
|
33
|
+
return Deno.env.get('RUN_SUPERVISOR_URL') || '';
|
|
34
|
+
})();
|
|
35
|
+
exports.enabled = (function () {
|
|
36
|
+
return Deno.env.get('RUN_SUPERVISOR_URL') ? true : false;
|
|
37
|
+
})();
|
|
38
|
+
const flows = (function () {
|
|
39
|
+
try {
|
|
40
|
+
const _cwd = Deno.cwd();
|
|
41
|
+
const flowsFile = Deno.readTextFileSync(_cwd + '/versori-flow.json');
|
|
42
|
+
const flows = JSON.parse(flowsFile);
|
|
43
|
+
const nodes = {};
|
|
44
|
+
for (const node of flows.nodes) {
|
|
45
|
+
nodes[node.id] = {
|
|
46
|
+
description: node?.data?.description,
|
|
47
|
+
steps: node?.data?.steps,
|
|
48
|
+
files: node?.data?.files[0],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return nodes;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return {};
|
|
55
|
+
}
|
|
56
|
+
})();
|
|
57
|
+
const logger = new ConsoleLogger_js_1.ConsoleLogger('debug');
|
|
58
|
+
function getTriggerData(workflow) {
|
|
59
|
+
if (workflow.trigger instanceof WebhookTrigger_js_1.WebhookTrigger) {
|
|
60
|
+
return {
|
|
61
|
+
id: workflow.trigger.id,
|
|
62
|
+
type: 'webhook',
|
|
63
|
+
method: workflow.trigger.options.method || 'post',
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
else if (workflow.trigger instanceof ScheduleTrigger_js_1.ScheduleTrigger) {
|
|
67
|
+
return {
|
|
68
|
+
id: workflow.trigger.id,
|
|
69
|
+
type: 'schedule',
|
|
70
|
+
schedule: workflow.trigger.schedule,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
else if (workflow.trigger instanceof DurableTrigger_js_1.DurableWorkflowTrigger) {
|
|
74
|
+
return {
|
|
75
|
+
id: workflow.trigger.id,
|
|
76
|
+
type: 'durable',
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
function getTaskData(task) {
|
|
82
|
+
let taskData = [];
|
|
83
|
+
if (task instanceof ChainTask_js_1.ChainTask) {
|
|
84
|
+
taskData = task.tasks.map((t) => getTaskData(t)).flat();
|
|
85
|
+
}
|
|
86
|
+
else if (task instanceof CatchTask_js_1.CatchTask) {
|
|
87
|
+
taskData = [...getTaskData(task._base), ...getTaskData(task._errorHandler)];
|
|
88
|
+
}
|
|
89
|
+
else if (task instanceof BackgroundTask_js_1.BackgroundTask) {
|
|
90
|
+
taskData = getTaskData(task._base);
|
|
91
|
+
}
|
|
92
|
+
else if (task instanceof ParallelTask_js_1.ParallelTask) {
|
|
93
|
+
// I'm not sure if this is correct, but I don't think there are any ParallelTasks out in the wild yet
|
|
94
|
+
taskData = [...getTaskData(task._base), ...getTaskData(task._each)];
|
|
95
|
+
}
|
|
96
|
+
else if (task instanceof FnTask_js_1.FnTask) {
|
|
97
|
+
taskData.push({
|
|
98
|
+
taskId: task.id,
|
|
99
|
+
type: task[Task_js_1.TaskType].toLowerCase(),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
else if (task instanceof HttpTask_js_1.HttpTaskImpl) {
|
|
103
|
+
taskData.push({
|
|
104
|
+
taskId: task.id,
|
|
105
|
+
type: task[Task_js_1.TaskType].toLowerCase(),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
// yolo
|
|
110
|
+
taskData.push({
|
|
111
|
+
taskId: String(task.id || 'unknown'),
|
|
112
|
+
type: task[Task_js_1.TaskType].toLowerCase(),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return taskData;
|
|
116
|
+
}
|
|
117
|
+
async function signalReady() {
|
|
118
|
+
if (!exports.enabled) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
await fetch(`${supervisorURL}/ready`, {
|
|
123
|
+
method: 'POST',
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
logger.error('Failed to signal ready to supervisor', { error: err });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
async function registerWorkflow(workflow) {
|
|
131
|
+
if (!exports.enabled) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const triggerData = getTriggerData(workflow);
|
|
135
|
+
const tasks = getTaskData(workflow.task);
|
|
136
|
+
try {
|
|
137
|
+
if (triggerData) {
|
|
138
|
+
const data = {
|
|
139
|
+
workflowId: triggerData.id,
|
|
140
|
+
trigger: triggerData,
|
|
141
|
+
tasks,
|
|
142
|
+
};
|
|
143
|
+
await fetch(`${supervisorURL}/register-workflow`, {
|
|
144
|
+
method: 'POST',
|
|
145
|
+
body: JSON.stringify(data),
|
|
146
|
+
headers: {
|
|
147
|
+
'Content-Type': 'application/json',
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch (err) {
|
|
153
|
+
logger.error('Failed to register workflow with supervisor', { error: err });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
async function sendTaskStartEvent(taskId, ctx, span) {
|
|
157
|
+
if (!exports.enabled) {
|
|
158
|
+
return ctx;
|
|
159
|
+
}
|
|
160
|
+
const data = {
|
|
161
|
+
taskId,
|
|
162
|
+
spanId: span.spanContext().spanId,
|
|
163
|
+
traceId: span.spanContext().traceId,
|
|
164
|
+
startTime: new Date().toISOString(), // assuming current time as start time
|
|
165
|
+
executionId: ctx.executionId,
|
|
166
|
+
workflowId: ctx.workflowId || '',
|
|
167
|
+
};
|
|
168
|
+
try {
|
|
169
|
+
const resp = await fetch(`${supervisorURL}/tasks/start`, {
|
|
170
|
+
method: 'POST',
|
|
171
|
+
body: JSON.stringify(data),
|
|
172
|
+
headers: {
|
|
173
|
+
'Content-Type': 'application/json',
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
if (resp.ok) {
|
|
177
|
+
const bodyString = await resp.text();
|
|
178
|
+
if (!bodyString) {
|
|
179
|
+
return ctx;
|
|
180
|
+
}
|
|
181
|
+
// TODO: XML, CSV yada yada
|
|
182
|
+
const respData = JSON.parse(bodyString);
|
|
183
|
+
return ctx.withData(respData);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
catch (err) {
|
|
187
|
+
logger.error('Failed to send task start event to supervisor', { error: err });
|
|
188
|
+
}
|
|
189
|
+
return ctx;
|
|
190
|
+
}
|
|
191
|
+
async function mockAPIRequest(info, cnx, options) {
|
|
192
|
+
if (!exports.enabled) {
|
|
193
|
+
return new Response();
|
|
194
|
+
}
|
|
195
|
+
const mockRequest = {
|
|
196
|
+
url: info.toString(),
|
|
197
|
+
payload: options?.body || '',
|
|
198
|
+
method: options?.method || 'GET',
|
|
199
|
+
headers: options?.headers,
|
|
200
|
+
connection: cnx?.name,
|
|
201
|
+
connectionId: cnx?.id,
|
|
202
|
+
};
|
|
203
|
+
try {
|
|
204
|
+
const response = await fetch(`${supervisorURL}/ai/fake-fetch-call`, {
|
|
205
|
+
method: 'POST',
|
|
206
|
+
body: JSON.stringify(mockRequest),
|
|
207
|
+
headers: {
|
|
208
|
+
'Content-Type': 'application/json',
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
if (!response.ok) {
|
|
212
|
+
logger.error('Failed to mock api request', { response });
|
|
213
|
+
return new Response();
|
|
214
|
+
}
|
|
215
|
+
const text = await response.text();
|
|
216
|
+
return new Response(text);
|
|
217
|
+
}
|
|
218
|
+
catch (err) {
|
|
219
|
+
logger.error('Failed to mock api request', { error: err });
|
|
220
|
+
return new Response();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function printableSpan(s) {
|
|
224
|
+
const span = {
|
|
225
|
+
name: s.name,
|
|
226
|
+
startTime: (0, core_1.hrTimeToTimeStamp)(s.startTime),
|
|
227
|
+
endTime: (0, core_1.hrTimeToTimeStamp)(s.endTime),
|
|
228
|
+
duration: (0, core_1.hrTimeToMilliseconds)(s.duration),
|
|
229
|
+
attributes: s.attributes,
|
|
230
|
+
status: s.status,
|
|
231
|
+
ended: s.ended,
|
|
232
|
+
events: s.events,
|
|
233
|
+
parentSpanContext: s.parentSpanContext,
|
|
234
|
+
spanContext: s.spanContext(),
|
|
235
|
+
};
|
|
236
|
+
const nodeDetail = flows[span.attributes['task.id']]; // I know I have coded all of those as string
|
|
237
|
+
if (nodeDetail) {
|
|
238
|
+
span.attributes['description'] = nodeDetail?.description || '';
|
|
239
|
+
span.attributes['steps'] = nodeDetail?.steps || '';
|
|
240
|
+
span.attributes['files'] = nodeDetail?.files || '';
|
|
241
|
+
}
|
|
242
|
+
return span;
|
|
243
|
+
}
|
|
244
|
+
class Fake {
|
|
245
|
+
constructor() {
|
|
246
|
+
this.export = this.export.bind(this);
|
|
247
|
+
this.shutdown = this.shutdown.bind(this);
|
|
248
|
+
this.forceFlush = this.forceFlush.bind(this);
|
|
249
|
+
}
|
|
250
|
+
export(spans, resultCallback) {
|
|
251
|
+
const ss = spans.map(printableSpan);
|
|
252
|
+
try {
|
|
253
|
+
fetch(`${supervisorURL}/receive-spans`, {
|
|
254
|
+
method: 'POST',
|
|
255
|
+
body: JSON.stringify({ spans: ss }),
|
|
256
|
+
headers: {
|
|
257
|
+
'Content-Type': 'application/json',
|
|
258
|
+
},
|
|
259
|
+
}).catch((err) => {
|
|
260
|
+
logger.error('Failed to send spans to supervisor', { error: err });
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
catch (err) {
|
|
264
|
+
logger.error('Failed to send spans to supervisor', { error: err });
|
|
265
|
+
}
|
|
266
|
+
resultCallback({ code: core_1.ExportResultCode.SUCCESS });
|
|
267
|
+
}
|
|
268
|
+
shutdown() {
|
|
269
|
+
return Promise.resolve();
|
|
270
|
+
}
|
|
271
|
+
forceFlush() {
|
|
272
|
+
return Promise.resolve();
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
exports.Fake = Fake;
|
|
@@ -46,6 +46,11 @@ type Registration = {
|
|
|
46
46
|
sigintListener: () => void;
|
|
47
47
|
subscription?: Subscription;
|
|
48
48
|
};
|
|
49
|
+
type WebhookRegistry = Map<string, {
|
|
50
|
+
method: string;
|
|
51
|
+
path: string;
|
|
52
|
+
options: any;
|
|
53
|
+
}>;
|
|
49
54
|
/**
|
|
50
55
|
* DurableInterpreter is an interpreter for executing Versori workflows with support for durable, queue-based workflow
|
|
51
56
|
* execution. It supports all trigger types including the {@link workflow} trigger which allows workflows to be started
|
|
@@ -76,7 +81,8 @@ export declare class DurableInterpreter {
|
|
|
76
81
|
private readonly contextProvider;
|
|
77
82
|
private readonly webhookRouter;
|
|
78
83
|
private readonly cronRouter;
|
|
79
|
-
private
|
|
84
|
+
private cronRegistry;
|
|
85
|
+
private webhookRegistry;
|
|
80
86
|
private readonly platformApi;
|
|
81
87
|
private readonly cnxFetchFactory;
|
|
82
88
|
private readonly cronProvider;
|
|
@@ -90,7 +96,8 @@ export declare class DurableInterpreter {
|
|
|
90
96
|
private cronServer?;
|
|
91
97
|
private shutdownServer?;
|
|
92
98
|
private isShuttingDown;
|
|
93
|
-
|
|
99
|
+
private wfRegistration;
|
|
100
|
+
constructor(log: Logger, compiler: ObservableCompiler, contextProvider: ContextProvider, webhookRouter: Router, cronRouter: Router, cronRegistry: Map<string, string>, webhookRegistry: WebhookRegistry, platformApi: PlatformApi, cnxFetchFactory: DirectConnectionFactory, cronProvider: CronProvider, tracer: Tracer, issue: IssueAPI, cfgReader: ConfigReader, queueProvider: QueueAPI, otelSDK?: NodeSDK | undefined);
|
|
94
101
|
static newInstance(options?: DurableInterpreterOptions): Promise<DurableInterpreter>;
|
|
95
102
|
register<O>(workflow: Workflow<O>, options?: DurableInterpreterOptions): Registration;
|
|
96
103
|
start(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DurableInterpreter.d.ts","sourceRoot":"","sources":["../../../../src/src/interpreter/durable/DurableInterpreter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DurableInterpreter.d.ts","sourceRoot":"","sources":["../../../../src/src/interpreter/durable/DurableInterpreter.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X,QAAQ,EAAE,kBAAkB,EAC5B,eAAe,EAAE,eAAe,EAChC,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,MAAM,EAC3B,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACjC,eAAe,EAAE,eAAe,EACvB,WAAW,EAAE,WAAW,EACxB,eAAe,EAAE,uBAAuB,EACxC,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,QAAQ,EACf,SAAS,EAAE,YAAY,EACvB,aAAa,EAAE,QAAQ,EACvB,OAAO,CAAC,EAAE,OAAO,YAAA;WAWzB,WAAW,CAAC,OAAO,GAAE,yBAA8B,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA+G9F,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,yBAAyB;IA+DhE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAkO5B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CASxB"}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DurableInterpreter = void 0;
|
|
2
7
|
/*
|
|
3
8
|
* Copyright (c) 2025 Versori Group Inc
|
|
4
9
|
*
|
|
@@ -11,11 +16,6 @@
|
|
|
11
16
|
* As of the Change Date, in accordance with the Business Source License,
|
|
12
17
|
* use of this software will be governed by the Apache License, Version 2.0.
|
|
13
18
|
*/
|
|
14
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
-
};
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.DurableInterpreter = void 0;
|
|
19
19
|
const api_1 = __importDefault(require("@opentelemetry/api"));
|
|
20
20
|
const exporter_trace_otlp_proto_1 = require("@opentelemetry/exporter-trace-otlp-proto");
|
|
21
21
|
const resources_1 = require("@opentelemetry/resources");
|
|
@@ -26,9 +26,10 @@ const CredentialsProvider_js_1 = require("../../connection/CredentialsProvider.j
|
|
|
26
26
|
const DirectConnectionFactory_js_1 = require("../../connection/DirectConnectionFactory.js");
|
|
27
27
|
const ContextProvider_js_1 = require("../../context/ContextProvider.js");
|
|
28
28
|
const configloader_js_1 = require("../../dsl/http/versori/configloader.js");
|
|
29
|
-
const constants_js_1 = require("../../dsl/http/versori/constants.js");
|
|
30
29
|
const cronapi_js_1 = require("../../dsl/http/versori/cronapi.js");
|
|
31
30
|
const Workflow_js_1 = require("../../dsl/Workflow.js");
|
|
31
|
+
const constants_js_1 = require("../../internal/constants.js");
|
|
32
|
+
const supervisor_js_1 = require("../../internal/supervisor.js");
|
|
32
33
|
const Issues_js_1 = require("../../issues/Issues.js");
|
|
33
34
|
const MemoryKeyValueProvider_js_1 = require("../../kv/memory/MemoryKeyValueProvider.js");
|
|
34
35
|
const SDKKeyValueProvider_js_1 = require("../../kv/sdk/SDKKeyValueProvider.js");
|
|
@@ -36,8 +37,8 @@ const ConsoleLogger_js_1 = require("../../observability/logging/ConsoleLogger.js
|
|
|
36
37
|
const PlatformApi_js_1 = require("../../services/platform/PlatformApi.js");
|
|
37
38
|
const ObservableCompiler_js_1 = require("./ObservableCompiler.js");
|
|
38
39
|
const Queue_js_1 = require("./Queue.js");
|
|
39
|
-
function getKVProvider(
|
|
40
|
-
if (
|
|
40
|
+
function getKVProvider() {
|
|
41
|
+
if (supervisor_js_1.enabled) {
|
|
41
42
|
return Promise.resolve(new MemoryKeyValueProvider_js_1.MemoryKeyValueProvider());
|
|
42
43
|
}
|
|
43
44
|
return SDKKeyValueProvider_js_1.SDKKeyValueProvider.fromEnv();
|
|
@@ -67,7 +68,7 @@ function getKVProvider(runLocal) {
|
|
|
67
68
|
* ```
|
|
68
69
|
*/
|
|
69
70
|
class DurableInterpreter {
|
|
70
|
-
constructor(log, compiler, contextProvider, webhookRouter, cronRouter, cronRegistry, platformApi, cnxFetchFactory, cronProvider, tracer, issue, cfgReader, queueProvider, otelSDK) {
|
|
71
|
+
constructor(log, compiler, contextProvider, webhookRouter, cronRouter, cronRegistry, webhookRegistry, platformApi, cnxFetchFactory, cronProvider, tracer, issue, cfgReader, queueProvider, otelSDK) {
|
|
71
72
|
Object.defineProperty(this, "log", {
|
|
72
73
|
enumerable: true,
|
|
73
74
|
configurable: true,
|
|
@@ -104,6 +105,12 @@ class DurableInterpreter {
|
|
|
104
105
|
writable: true,
|
|
105
106
|
value: cronRegistry
|
|
106
107
|
});
|
|
108
|
+
Object.defineProperty(this, "webhookRegistry", {
|
|
109
|
+
enumerable: true,
|
|
110
|
+
configurable: true,
|
|
111
|
+
writable: true,
|
|
112
|
+
value: webhookRegistry
|
|
113
|
+
});
|
|
107
114
|
Object.defineProperty(this, "platformApi", {
|
|
108
115
|
enumerable: true,
|
|
109
116
|
configurable: true,
|
|
@@ -182,6 +189,13 @@ class DurableInterpreter {
|
|
|
182
189
|
writable: true,
|
|
183
190
|
value: false
|
|
184
191
|
});
|
|
192
|
+
// Workflow registration promises only used when supervisor is enabled
|
|
193
|
+
Object.defineProperty(this, "wfRegistration", {
|
|
194
|
+
enumerable: true,
|
|
195
|
+
configurable: true,
|
|
196
|
+
writable: true,
|
|
197
|
+
value: []
|
|
198
|
+
});
|
|
185
199
|
if (typeof this.log === 'undefined') {
|
|
186
200
|
// this captures the old way of instantiating the DurableInterpreter and provides an
|
|
187
201
|
// error message back to the user to let them know they should use the new way.
|
|
@@ -200,7 +214,6 @@ class DurableInterpreter {
|
|
|
200
214
|
const otelTracesURL = Deno.env.get(constants_js_1.envVarOtelTracesURL);
|
|
201
215
|
let otelSDK;
|
|
202
216
|
const configReader = configloader_js_1.VersoriConfigReader.fromEnv(log);
|
|
203
|
-
const runLocal = Deno.env.get(constants_js_1.envVarLocalRun) === 'true';
|
|
204
217
|
await waitForReady(log);
|
|
205
218
|
// Do NOT change those attributes, they are used by the API to filter on
|
|
206
219
|
const resource = (0, resources_1.resourceFromAttributes)({
|
|
@@ -222,6 +235,15 @@ class DurableInterpreter {
|
|
|
222
235
|
log.info('Starting OpenTelemetry SDK');
|
|
223
236
|
otelSDK.start();
|
|
224
237
|
}
|
|
238
|
+
else if (supervisor_js_1.enabled) {
|
|
239
|
+
otelSDK = new sdk_node_1.NodeSDK({
|
|
240
|
+
traceExporter: new supervisor_js_1.Fake(),
|
|
241
|
+
serviceName: serviceName,
|
|
242
|
+
resource: resource,
|
|
243
|
+
});
|
|
244
|
+
log.info('Starting Testing OpenTelemetry SDK');
|
|
245
|
+
otelSDK.start();
|
|
246
|
+
}
|
|
225
247
|
const tracer = api_1.default.trace.getTracer(serviceName, version);
|
|
226
248
|
const queueProvider = await Queue_js_1.QueueImpl.fromEnv(log);
|
|
227
249
|
const connectionFactory = DirectConnectionFactory_js_1.DirectConnectionFactory.fromEnv(log);
|
|
@@ -229,14 +251,14 @@ class DurableInterpreter {
|
|
|
229
251
|
if (options.contextProvider) {
|
|
230
252
|
// no need to set up a key-value provider if options.contextProvider is already
|
|
231
253
|
// initialised.
|
|
232
|
-
return new DurableInterpreter(log, compiler, options.contextProvider, express_1.default.Router(), express_1.default.Router(), new Map(), PlatformApi_js_1.PlatformApiImpl.fromEnv(), connectionFactory, cronapi_js_1.CronAPIClient.fromEnv(), tracer, issuesProvider, configReader, queueProvider, otelSDK);
|
|
254
|
+
return new DurableInterpreter(log, compiler, options.contextProvider, express_1.default.Router(), express_1.default.Router(), new Map(), new Map(), PlatformApi_js_1.PlatformApiImpl.fromEnv(), connectionFactory, cronapi_js_1.CronAPIClient.fromEnv(), tracer, issuesProvider, configReader, queueProvider, otelSDK);
|
|
233
255
|
}
|
|
234
|
-
const kvp = await getKVProvider(
|
|
256
|
+
const kvp = await getKVProvider();
|
|
235
257
|
const platformApi = PlatformApi_js_1.PlatformApiImpl.fromEnv();
|
|
236
258
|
const organisationId = Deno.env.get(constants_js_1.envVarOrgId) || 'development';
|
|
237
259
|
const environmentId = Deno.env.get(constants_js_1.envVarEnvId) || 'development';
|
|
238
260
|
const ctxProvider = new ContextProvider_js_1.ContextProviderImpl(log, kvp, new CredentialsProvider_js_1.CredentialsProviderImpl(connectionFactory.credentials, connectionFactory.tokens, connectionFactory.oauth1, configReader, platformApi), platformApi, organisationId, environmentId, issuesProvider, queueProvider);
|
|
239
|
-
return new DurableInterpreter(log, compiler, ctxProvider, express_1.default.Router(), express_1.default.Router(), new Map(), PlatformApi_js_1.PlatformApiImpl.fromEnv(), connectionFactory, cronapi_js_1.CronAPIClient.fromEnv(), tracer, issuesProvider, configReader, queueProvider, otelSDK);
|
|
261
|
+
return new DurableInterpreter(log, compiler, ctxProvider, express_1.default.Router(), express_1.default.Router(), new Map(), new Map(), PlatformApi_js_1.PlatformApiImpl.fromEnv(), connectionFactory, cronapi_js_1.CronAPIClient.fromEnv(), tracer, issuesProvider, configReader, queueProvider, otelSDK);
|
|
240
262
|
}
|
|
241
263
|
register(workflow, options) {
|
|
242
264
|
const localAbortController = new AbortController();
|
|
@@ -256,6 +278,7 @@ class DurableInterpreter {
|
|
|
256
278
|
tracer: this.tracer,
|
|
257
279
|
contextProvider: this.contextProvider,
|
|
258
280
|
webhookRouter: this.webhookRouter,
|
|
281
|
+
webhookRegistry: this.webhookRegistry,
|
|
259
282
|
queueProvider: this.queueProvider,
|
|
260
283
|
cronRouter: this.cronRouter,
|
|
261
284
|
cronRegistry: this.cronRegistry,
|
|
@@ -278,11 +301,14 @@ class DurableInterpreter {
|
|
|
278
301
|
},
|
|
279
302
|
};
|
|
280
303
|
this.registeredWorkflows.push(registration);
|
|
304
|
+
if (supervisor_js_1.enabled) {
|
|
305
|
+
this.wfRegistration.push((0, supervisor_js_1.registerWorkflow)(workflow));
|
|
306
|
+
}
|
|
281
307
|
return registration;
|
|
282
308
|
}
|
|
283
|
-
start() {
|
|
284
|
-
const port = Deno.env.get(
|
|
285
|
-
const cronPort = Deno.env.get(
|
|
309
|
+
async start() {
|
|
310
|
+
const port = Deno.env.get(constants_js_1.envPort) || 3000;
|
|
311
|
+
const cronPort = Deno.env.get(constants_js_1.envCronPort) || 3001;
|
|
286
312
|
const webhookApp = (0, express_1.default)();
|
|
287
313
|
const cronApp = (0, express_1.default)();
|
|
288
314
|
cronApp.use(express_1.default.json());
|
|
@@ -309,11 +335,18 @@ class DurableInterpreter {
|
|
|
309
335
|
triggerName: registration.triggerName,
|
|
310
336
|
error: err instanceof Error ? err.toString() : err,
|
|
311
337
|
});
|
|
338
|
+
this.tracer.startActiveSpan('done', (span) => {
|
|
339
|
+
span.setAttribute('error.message', err instanceof Error ? err.toString() : err);
|
|
340
|
+
span.setAttribute('execution.id', ctx.executionId);
|
|
341
|
+
span.setAttribute('result', 'fail');
|
|
342
|
+
span.setAttribute('workflow.id', ctx.workflowId || 'unknown-workflow');
|
|
343
|
+
span.end();
|
|
344
|
+
});
|
|
312
345
|
try {
|
|
313
346
|
ctx.options.onError?.(ctx.withData(err));
|
|
314
347
|
}
|
|
315
348
|
catch (err) {
|
|
316
|
-
ctx.log.error('DurableInterpreter.
|
|
349
|
+
ctx.log.error('DurableInterpreter.onError: failed to call onError handler', {
|
|
317
350
|
triggerName: registration.triggerName,
|
|
318
351
|
error: err instanceof Error ? err.toString() : err,
|
|
319
352
|
});
|
|
@@ -331,6 +364,12 @@ class DurableInterpreter {
|
|
|
331
364
|
triggerName: registration.triggerName,
|
|
332
365
|
durationMs,
|
|
333
366
|
});
|
|
367
|
+
this.tracer.startActiveSpan('done', (span) => {
|
|
368
|
+
span.setAttribute('execution.id', ctx.executionId);
|
|
369
|
+
span.setAttribute('result', 'pass');
|
|
370
|
+
span.setAttribute('workflow.id', ctx.workflowId || 'unknown-workflow');
|
|
371
|
+
span.end();
|
|
372
|
+
});
|
|
334
373
|
try {
|
|
335
374
|
ctx.options.onSuccess?.(ctx);
|
|
336
375
|
}
|
|
@@ -392,6 +431,7 @@ class DurableInterpreter {
|
|
|
392
431
|
if (this.cronServer) {
|
|
393
432
|
this.cronServer.close();
|
|
394
433
|
}
|
|
434
|
+
this.otelSDK?.shutdown();
|
|
395
435
|
// Remove all signal listeners
|
|
396
436
|
for (const registration of this.registeredWorkflows) {
|
|
397
437
|
Deno.removeSignalListener('SIGINT', registration.sigintListener);
|
|
@@ -408,6 +448,10 @@ class DurableInterpreter {
|
|
|
408
448
|
}
|
|
409
449
|
};
|
|
410
450
|
Deno.addSignalListener('SIGINT', this.shutdownServer);
|
|
451
|
+
if (supervisor_js_1.enabled) {
|
|
452
|
+
await Promise.all(this.wfRegistration);
|
|
453
|
+
await (0, supervisor_js_1.signalReady)();
|
|
454
|
+
}
|
|
411
455
|
return new Promise((resolve) => {
|
|
412
456
|
let serversClosed = 0;
|
|
413
457
|
const totalServers = [this.webhookServer, this.cronServer].filter(Boolean).length;
|
|
@@ -445,7 +489,7 @@ class DurableInterpreter {
|
|
|
445
489
|
}
|
|
446
490
|
exports.DurableInterpreter = DurableInterpreter;
|
|
447
491
|
async function waitForReady(log) {
|
|
448
|
-
const readyCheckUrl = Deno.env.get(
|
|
492
|
+
const readyCheckUrl = Deno.env.get(constants_js_1.envReadyCheckURL);
|
|
449
493
|
if (!readyCheckUrl) {
|
|
450
494
|
return Promise.resolve();
|
|
451
495
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Tracer } from '@opentelemetry/api';
|
|
2
2
|
import { Router } from 'express';
|
|
3
3
|
import { Observable, OperatorFunction } from 'rxjs';
|
|
4
|
+
import { ConnectionFactory } from '../../connection/types.js';
|
|
4
5
|
import { ContextImpl } from '../../context/Context.js';
|
|
5
6
|
import { ContextProvider } from '../../context/ContextProvider.js';
|
|
6
7
|
import { ConfigReader } from '../../dsl/http/types.js';
|
|
@@ -11,7 +12,6 @@ import { Logger } from '../../observability/logging/Logger.js';
|
|
|
11
12
|
import { PlatformApi } from '../../services/platform/mod.js';
|
|
12
13
|
import { ContextOperatorFunction, TaskCompiler, TriggerCompiler } from './compilers/types.js';
|
|
13
14
|
import { QueueAPI } from './Queue.js';
|
|
14
|
-
import { ConnectionFactory } from '../../connection/types.js';
|
|
15
15
|
export type DurableCompilerContext = {
|
|
16
16
|
compiler: ObservableCompiler;
|
|
17
17
|
log: Logger;
|
|
@@ -22,6 +22,11 @@ export type DurableCompilerContext = {
|
|
|
22
22
|
queueProvider: QueueAPI;
|
|
23
23
|
issueProvider: IssueAPI;
|
|
24
24
|
webhookRouter: Router;
|
|
25
|
+
webhookRegistry: Map<string, {
|
|
26
|
+
method: string;
|
|
27
|
+
path: string;
|
|
28
|
+
options: any;
|
|
29
|
+
}>;
|
|
25
30
|
cronRouter: Router;
|
|
26
31
|
configReader: ConfigReader;
|
|
27
32
|
cronRegistry: Map<string, string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObservableCompiler.d.ts","sourceRoot":"","sources":["../../../../src/src/interpreter/durable/ObservableCompiler.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAY,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAe,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,uCAAuC,CAAC;AAC/D,OAAO,EAAE,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AAE,IAAI,CAAC,CAAC;IAerC,YAAY,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,SAAS,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;IAKjF,eAAe,CAAC,GAAG,EAAE,CAAC,SAAS,OAAO,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,eAAe,CAAC,GAAG,EAAE,CAAC,CAAC;CAIjF"}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.MockQueue = exports.QueueImpl = void 0;
|
|
16
|
-
const constants_js_1 = require("../../
|
|
16
|
+
const constants_js_1 = require("../../internal/constants.js");
|
|
17
17
|
const mod_js_1 = require("../../mod.js");
|
|
18
18
|
class QueueImpl {
|
|
19
19
|
constructor(baseUrl, projectId, environmentId, log) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catch.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/catch.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAG5D,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"catch.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/catch.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAG5D,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AAyFnE,eAAO,MAAM,aAAa,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,CAGrE,CAAC"}
|
|
@@ -25,7 +25,9 @@ function compileCatch(compilerCtx, task) {
|
|
|
25
25
|
return compilerCtx.tracer.startActiveSpan(`catch`, (span) => {
|
|
26
26
|
span.setAttribute('execution.id', ctx.executionId);
|
|
27
27
|
span.setAttribute('task.type', 'catch');
|
|
28
|
+
span.setAttribute('type', 'task');
|
|
28
29
|
if (error instanceof Error) {
|
|
30
|
+
span.setAttribute('status', 'fail');
|
|
29
31
|
span.recordException(error);
|
|
30
32
|
span.setAttribute('error.message', error.message);
|
|
31
33
|
span.setAttribute('error.stack', error.stack ?? '');
|
|
@@ -63,7 +65,7 @@ function compileCatch(compilerCtx, task) {
|
|
|
63
65
|
reason: 'error',
|
|
64
66
|
severity: 'low',
|
|
65
67
|
});
|
|
66
|
-
span.setAttribute('
|
|
68
|
+
span.setAttribute('status', 'fail');
|
|
67
69
|
span.end();
|
|
68
70
|
return errorOperator((0, rxjs_1.of)(ctx.withData(new ExecutionError_js_1.ExecutionError(ctx, `${error}`, { cause: error }), { recoveredFromCatch: true })));
|
|
69
71
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fn.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/fn.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fn.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/fn.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAGtD,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AAoDnE,eAAO,MAAM,UAAU,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAG/D,CAAC"}
|
|
@@ -15,18 +15,41 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.fnCompiler = void 0;
|
|
16
16
|
const rxjs_1 = require("rxjs");
|
|
17
17
|
const FnTask_js_1 = require("../../../dsl/tasks/FnTask.js");
|
|
18
|
+
const supervisor_js_1 = require("../../../internal/supervisor.js");
|
|
18
19
|
function compileFn(compilerCtx, task) {
|
|
19
|
-
return (src) => src.pipe((0, rxjs_1.
|
|
20
|
-
complete: () => compilerCtx.log.debug('fn.complete'),
|
|
21
|
-
}), (0, rxjs_1.mergeMap)(async (ctx) => {
|
|
20
|
+
return (src) => src.pipe((0, rxjs_1.mergeMap)(async (ctx) => {
|
|
22
21
|
return await compilerCtx.tracer.startActiveSpan(`fn-${task.id}`, async (span) => {
|
|
22
|
+
await (0, supervisor_js_1.sendTaskStartEvent)(task.id, ctx, span);
|
|
23
23
|
span.setAttribute('task.id', task.id);
|
|
24
|
+
span.setAttribute('type', 'task');
|
|
25
|
+
span.setAttribute('task.type', 'fn');
|
|
24
26
|
span.setAttribute('execution.id', ctx.executionId);
|
|
27
|
+
span.setAttribute('workflow.id', ctx.options.workflowId || 'unknown-workflow');
|
|
25
28
|
try {
|
|
29
|
+
const spanContext = span.spanContext();
|
|
30
|
+
const ctxWithLogger = ctx.withLogger(ctx.log.child({ spanId: spanContext.spanId, traceId: spanContext.traceId }));
|
|
31
|
+
let result;
|
|
26
32
|
if (typeof ctx.idx === 'number') {
|
|
27
|
-
|
|
33
|
+
result = ctx.withData(await task._fn(ctxWithLogger, ctx.idx));
|
|
28
34
|
}
|
|
29
|
-
|
|
35
|
+
else {
|
|
36
|
+
result = ctx.withData(await task._fn(ctxWithLogger));
|
|
37
|
+
}
|
|
38
|
+
if (supervisor_js_1.enabled) {
|
|
39
|
+
span.setAttribute('response.body', JSON.stringify(result.data));
|
|
40
|
+
}
|
|
41
|
+
span.setAttribute('status', 'pass');
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (error instanceof Error) {
|
|
46
|
+
span.setAttribute('status', 'fail');
|
|
47
|
+
span.recordException(error);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
span.recordException(new Error(String(error)));
|
|
51
|
+
}
|
|
52
|
+
throw error;
|
|
30
53
|
}
|
|
31
54
|
finally {
|
|
32
55
|
span.end();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/http.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/http.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAmB,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAG/E,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AAyHnE,eAAO,MAAM,YAAY,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAG5E,CAAC"}
|