@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,267 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Versori Group Inc
|
|
3
|
+
*
|
|
4
|
+
* Use of this software is governed by the Business Source License 1.1
|
|
5
|
+
* included in the LICENSE file at the root of this repository.
|
|
6
|
+
*
|
|
7
|
+
* Change Date: 2029-01-01
|
|
8
|
+
* Change License: Apache License, Version 2.0
|
|
9
|
+
*
|
|
10
|
+
* As of the Change Date, in accordance with the Business Source License,
|
|
11
|
+
* use of this software will be governed by the Apache License, Version 2.0.
|
|
12
|
+
*/
|
|
13
|
+
import { ExportResultCode, hrTimeToMilliseconds, hrTimeToTimeStamp, } from '@opentelemetry/core';
|
|
14
|
+
import { ConsoleLogger } from '../observability/logging/ConsoleLogger.js';
|
|
15
|
+
import { ChainTask } from '../dsl/tasks/ChainTask.js';
|
|
16
|
+
import { ScheduleTrigger } from '../dsl/triggers/ScheduleTrigger.js';
|
|
17
|
+
import { WebhookTrigger } from '../dsl/triggers/WebhookTrigger.js';
|
|
18
|
+
import { DurableWorkflowTrigger } from '../dsl/triggers/DurableTrigger.js';
|
|
19
|
+
import { TaskType } from '../dsl/Task.js';
|
|
20
|
+
import { CatchTask } from '../dsl/tasks/CatchTask.js';
|
|
21
|
+
import { FnTask } from '../dsl/tasks/FnTask.js';
|
|
22
|
+
import { HttpTaskImpl } from '../dsl/tasks/HttpTask.js';
|
|
23
|
+
import { BackgroundTask } from '../dsl/tasks/BackgroundTask.js';
|
|
24
|
+
import { ParallelTask } from '../dsl/tasks/ParallelTask.js';
|
|
25
|
+
const supervisorURL = (function () {
|
|
26
|
+
return Deno.env.get('RUN_SUPERVISOR_URL') || '';
|
|
27
|
+
})();
|
|
28
|
+
export const enabled = (function () {
|
|
29
|
+
return Deno.env.get('RUN_SUPERVISOR_URL') ? true : false;
|
|
30
|
+
})();
|
|
31
|
+
const flows = (function () {
|
|
32
|
+
try {
|
|
33
|
+
const _cwd = Deno.cwd();
|
|
34
|
+
const flowsFile = Deno.readTextFileSync(_cwd + '/versori-flow.json');
|
|
35
|
+
const flows = JSON.parse(flowsFile);
|
|
36
|
+
const nodes = {};
|
|
37
|
+
for (const node of flows.nodes) {
|
|
38
|
+
nodes[node.id] = {
|
|
39
|
+
description: node?.data?.description,
|
|
40
|
+
steps: node?.data?.steps,
|
|
41
|
+
files: node?.data?.files[0],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return nodes;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
})();
|
|
50
|
+
const logger = new ConsoleLogger('debug');
|
|
51
|
+
function getTriggerData(workflow) {
|
|
52
|
+
if (workflow.trigger instanceof WebhookTrigger) {
|
|
53
|
+
return {
|
|
54
|
+
id: workflow.trigger.id,
|
|
55
|
+
type: 'webhook',
|
|
56
|
+
method: workflow.trigger.options.method || 'post',
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
else if (workflow.trigger instanceof ScheduleTrigger) {
|
|
60
|
+
return {
|
|
61
|
+
id: workflow.trigger.id,
|
|
62
|
+
type: 'schedule',
|
|
63
|
+
schedule: workflow.trigger.schedule,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
else if (workflow.trigger instanceof DurableWorkflowTrigger) {
|
|
67
|
+
return {
|
|
68
|
+
id: workflow.trigger.id,
|
|
69
|
+
type: 'durable',
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
function getTaskData(task) {
|
|
75
|
+
let taskData = [];
|
|
76
|
+
if (task instanceof ChainTask) {
|
|
77
|
+
taskData = task.tasks.map((t) => getTaskData(t)).flat();
|
|
78
|
+
}
|
|
79
|
+
else if (task instanceof CatchTask) {
|
|
80
|
+
taskData = [...getTaskData(task._base), ...getTaskData(task._errorHandler)];
|
|
81
|
+
}
|
|
82
|
+
else if (task instanceof BackgroundTask) {
|
|
83
|
+
taskData = getTaskData(task._base);
|
|
84
|
+
}
|
|
85
|
+
else if (task instanceof ParallelTask) {
|
|
86
|
+
// I'm not sure if this is correct, but I don't think there are any ParallelTasks out in the wild yet
|
|
87
|
+
taskData = [...getTaskData(task._base), ...getTaskData(task._each)];
|
|
88
|
+
}
|
|
89
|
+
else if (task instanceof FnTask) {
|
|
90
|
+
taskData.push({
|
|
91
|
+
taskId: task.id,
|
|
92
|
+
type: task[TaskType].toLowerCase(),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
else if (task instanceof HttpTaskImpl) {
|
|
96
|
+
taskData.push({
|
|
97
|
+
taskId: task.id,
|
|
98
|
+
type: task[TaskType].toLowerCase(),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
// yolo
|
|
103
|
+
taskData.push({
|
|
104
|
+
taskId: String(task.id || 'unknown'),
|
|
105
|
+
type: task[TaskType].toLowerCase(),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return taskData;
|
|
109
|
+
}
|
|
110
|
+
export async function signalReady() {
|
|
111
|
+
if (!enabled) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
await fetch(`${supervisorURL}/ready`, {
|
|
116
|
+
method: 'POST',
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
logger.error('Failed to signal ready to supervisor', { error: err });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export async function registerWorkflow(workflow) {
|
|
124
|
+
if (!enabled) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const triggerData = getTriggerData(workflow);
|
|
128
|
+
const tasks = getTaskData(workflow.task);
|
|
129
|
+
try {
|
|
130
|
+
if (triggerData) {
|
|
131
|
+
const data = {
|
|
132
|
+
workflowId: triggerData.id,
|
|
133
|
+
trigger: triggerData,
|
|
134
|
+
tasks,
|
|
135
|
+
};
|
|
136
|
+
await fetch(`${supervisorURL}/register-workflow`, {
|
|
137
|
+
method: 'POST',
|
|
138
|
+
body: JSON.stringify(data),
|
|
139
|
+
headers: {
|
|
140
|
+
'Content-Type': 'application/json',
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
logger.error('Failed to register workflow with supervisor', { error: err });
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
export async function sendTaskStartEvent(taskId, ctx, span) {
|
|
150
|
+
if (!enabled) {
|
|
151
|
+
return ctx;
|
|
152
|
+
}
|
|
153
|
+
const data = {
|
|
154
|
+
taskId,
|
|
155
|
+
spanId: span.spanContext().spanId,
|
|
156
|
+
traceId: span.spanContext().traceId,
|
|
157
|
+
startTime: new Date().toISOString(), // assuming current time as start time
|
|
158
|
+
executionId: ctx.executionId,
|
|
159
|
+
workflowId: ctx.workflowId || '',
|
|
160
|
+
};
|
|
161
|
+
try {
|
|
162
|
+
const resp = await fetch(`${supervisorURL}/tasks/start`, {
|
|
163
|
+
method: 'POST',
|
|
164
|
+
body: JSON.stringify(data),
|
|
165
|
+
headers: {
|
|
166
|
+
'Content-Type': 'application/json',
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
if (resp.ok) {
|
|
170
|
+
const bodyString = await resp.text();
|
|
171
|
+
if (!bodyString) {
|
|
172
|
+
return ctx;
|
|
173
|
+
}
|
|
174
|
+
// TODO: XML, CSV yada yada
|
|
175
|
+
const respData = JSON.parse(bodyString);
|
|
176
|
+
return ctx.withData(respData);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
catch (err) {
|
|
180
|
+
logger.error('Failed to send task start event to supervisor', { error: err });
|
|
181
|
+
}
|
|
182
|
+
return ctx;
|
|
183
|
+
}
|
|
184
|
+
export async function mockAPIRequest(info, cnx, options) {
|
|
185
|
+
if (!enabled) {
|
|
186
|
+
return new Response();
|
|
187
|
+
}
|
|
188
|
+
const mockRequest = {
|
|
189
|
+
url: info.toString(),
|
|
190
|
+
payload: options?.body || '',
|
|
191
|
+
method: options?.method || 'GET',
|
|
192
|
+
headers: options?.headers,
|
|
193
|
+
connection: cnx?.name,
|
|
194
|
+
connectionId: cnx?.id,
|
|
195
|
+
};
|
|
196
|
+
try {
|
|
197
|
+
const response = await fetch(`${supervisorURL}/ai/fake-fetch-call`, {
|
|
198
|
+
method: 'POST',
|
|
199
|
+
body: JSON.stringify(mockRequest),
|
|
200
|
+
headers: {
|
|
201
|
+
'Content-Type': 'application/json',
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
if (!response.ok) {
|
|
205
|
+
logger.error('Failed to mock api request', { response });
|
|
206
|
+
return new Response();
|
|
207
|
+
}
|
|
208
|
+
const text = await response.text();
|
|
209
|
+
return new Response(text);
|
|
210
|
+
}
|
|
211
|
+
catch (err) {
|
|
212
|
+
logger.error('Failed to mock api request', { error: err });
|
|
213
|
+
return new Response();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function printableSpan(s) {
|
|
217
|
+
const span = {
|
|
218
|
+
name: s.name,
|
|
219
|
+
startTime: hrTimeToTimeStamp(s.startTime),
|
|
220
|
+
endTime: hrTimeToTimeStamp(s.endTime),
|
|
221
|
+
duration: hrTimeToMilliseconds(s.duration),
|
|
222
|
+
attributes: s.attributes,
|
|
223
|
+
status: s.status,
|
|
224
|
+
ended: s.ended,
|
|
225
|
+
events: s.events,
|
|
226
|
+
parentSpanContext: s.parentSpanContext,
|
|
227
|
+
spanContext: s.spanContext(),
|
|
228
|
+
};
|
|
229
|
+
const nodeDetail = flows[span.attributes['task.id']]; // I know I have coded all of those as string
|
|
230
|
+
if (nodeDetail) {
|
|
231
|
+
span.attributes['description'] = nodeDetail?.description || '';
|
|
232
|
+
span.attributes['steps'] = nodeDetail?.steps || '';
|
|
233
|
+
span.attributes['files'] = nodeDetail?.files || '';
|
|
234
|
+
}
|
|
235
|
+
return span;
|
|
236
|
+
}
|
|
237
|
+
export class Fake {
|
|
238
|
+
constructor() {
|
|
239
|
+
this.export = this.export.bind(this);
|
|
240
|
+
this.shutdown = this.shutdown.bind(this);
|
|
241
|
+
this.forceFlush = this.forceFlush.bind(this);
|
|
242
|
+
}
|
|
243
|
+
export(spans, resultCallback) {
|
|
244
|
+
const ss = spans.map(printableSpan);
|
|
245
|
+
try {
|
|
246
|
+
fetch(`${supervisorURL}/receive-spans`, {
|
|
247
|
+
method: 'POST',
|
|
248
|
+
body: JSON.stringify({ spans: ss }),
|
|
249
|
+
headers: {
|
|
250
|
+
'Content-Type': 'application/json',
|
|
251
|
+
},
|
|
252
|
+
}).catch((err) => {
|
|
253
|
+
logger.error('Failed to send spans to supervisor', { error: err });
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
catch (err) {
|
|
257
|
+
logger.error('Failed to send spans to supervisor', { error: err });
|
|
258
|
+
}
|
|
259
|
+
resultCallback({ code: ExportResultCode.SUCCESS });
|
|
260
|
+
}
|
|
261
|
+
shutdown() {
|
|
262
|
+
return Promise.resolve();
|
|
263
|
+
}
|
|
264
|
+
forceFlush() {
|
|
265
|
+
return Promise.resolve();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
@@ -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.ts"],"names":[],"mappings":"AAYA,OAAsB,EAAQ,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAGjE,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAgB,EAAqB,MAAM,EAAE,MAAM,SAAS,CAAC;AAE7D,OAAO,EAA+B,UAAU,EAAM,YAAY,EAAO,MAAM,MAAM,CAAC;AAEtF,OAAO,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAC;AACtF,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,eAAe,EAAuB,MAAM,kCAAkC,CAAC;AACxF,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAGrE,OAAO,EAAE,QAA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C,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"}
|
|
@@ -20,9 +20,10 @@ import { CredentialsProviderImpl } from '../../connection/CredentialsProvider.js
|
|
|
20
20
|
import { DirectConnectionFactory } from '../../connection/DirectConnectionFactory.js';
|
|
21
21
|
import { ContextProviderImpl } from '../../context/ContextProvider.js';
|
|
22
22
|
import { VersoriConfigReader } from '../../dsl/http/versori/configloader.js';
|
|
23
|
-
import { envVarEnvId, envVarEnvironmentName, envVarLocalRun, envVarOrgId, envVarOrgSlug, envVarOtelTracesURL, envVarProjectId, envVarVersion, } from '../../dsl/http/versori/constants.js';
|
|
24
23
|
import { CronAPIClient } from '../../dsl/http/versori/cronapi.js';
|
|
25
24
|
import { WorkflowImpl } from '../../dsl/Workflow.js';
|
|
25
|
+
import { envCronPort, envPort, envReadyCheckURL, envVarEnvId, envVarEnvironmentName, envVarOrgId, envVarOrgSlug, envVarOtelTracesURL, envVarProjectId, envVarVersion, } from '../../internal/constants.js';
|
|
26
|
+
import { Fake, registerWorkflow, signalReady, enabled as supervisorEnabled } from '../../internal/supervisor.js';
|
|
26
27
|
import { IssueImpl } from '../../issues/Issues.js';
|
|
27
28
|
import { MemoryKeyValueProvider } from '../../kv/memory/MemoryKeyValueProvider.js';
|
|
28
29
|
import { SDKKeyValueProvider } from '../../kv/sdk/SDKKeyValueProvider.js';
|
|
@@ -30,8 +31,8 @@ import { ConsoleLogger } from '../../observability/logging/ConsoleLogger.js';
|
|
|
30
31
|
import { PlatformApiImpl } from '../../services/platform/PlatformApi.js';
|
|
31
32
|
import { ObservableCompiler } from './ObservableCompiler.js';
|
|
32
33
|
import { QueueImpl } from './Queue.js';
|
|
33
|
-
function getKVProvider(
|
|
34
|
-
if (
|
|
34
|
+
function getKVProvider() {
|
|
35
|
+
if (supervisorEnabled) {
|
|
35
36
|
return Promise.resolve(new MemoryKeyValueProvider());
|
|
36
37
|
}
|
|
37
38
|
return SDKKeyValueProvider.fromEnv();
|
|
@@ -61,7 +62,7 @@ function getKVProvider(runLocal) {
|
|
|
61
62
|
* ```
|
|
62
63
|
*/
|
|
63
64
|
export class DurableInterpreter {
|
|
64
|
-
constructor(log, compiler, contextProvider, webhookRouter, cronRouter, cronRegistry, platformApi, cnxFetchFactory, cronProvider, tracer, issue, cfgReader, queueProvider, otelSDK) {
|
|
65
|
+
constructor(log, compiler, contextProvider, webhookRouter, cronRouter, cronRegistry, webhookRegistry, platformApi, cnxFetchFactory, cronProvider, tracer, issue, cfgReader, queueProvider, otelSDK) {
|
|
65
66
|
Object.defineProperty(this, "log", {
|
|
66
67
|
enumerable: true,
|
|
67
68
|
configurable: true,
|
|
@@ -98,6 +99,12 @@ export class DurableInterpreter {
|
|
|
98
99
|
writable: true,
|
|
99
100
|
value: cronRegistry
|
|
100
101
|
});
|
|
102
|
+
Object.defineProperty(this, "webhookRegistry", {
|
|
103
|
+
enumerable: true,
|
|
104
|
+
configurable: true,
|
|
105
|
+
writable: true,
|
|
106
|
+
value: webhookRegistry
|
|
107
|
+
});
|
|
101
108
|
Object.defineProperty(this, "platformApi", {
|
|
102
109
|
enumerable: true,
|
|
103
110
|
configurable: true,
|
|
@@ -176,6 +183,13 @@ export class DurableInterpreter {
|
|
|
176
183
|
writable: true,
|
|
177
184
|
value: false
|
|
178
185
|
});
|
|
186
|
+
// Workflow registration promises only used when supervisor is enabled
|
|
187
|
+
Object.defineProperty(this, "wfRegistration", {
|
|
188
|
+
enumerable: true,
|
|
189
|
+
configurable: true,
|
|
190
|
+
writable: true,
|
|
191
|
+
value: []
|
|
192
|
+
});
|
|
179
193
|
if (typeof this.log === 'undefined') {
|
|
180
194
|
// this captures the old way of instantiating the DurableInterpreter and provides an
|
|
181
195
|
// error message back to the user to let them know they should use the new way.
|
|
@@ -194,7 +208,6 @@ export class DurableInterpreter {
|
|
|
194
208
|
const otelTracesURL = Deno.env.get(envVarOtelTracesURL);
|
|
195
209
|
let otelSDK;
|
|
196
210
|
const configReader = VersoriConfigReader.fromEnv(log);
|
|
197
|
-
const runLocal = Deno.env.get(envVarLocalRun) === 'true';
|
|
198
211
|
await waitForReady(log);
|
|
199
212
|
// Do NOT change those attributes, they are used by the API to filter on
|
|
200
213
|
const resource = resourceFromAttributes({
|
|
@@ -216,6 +229,15 @@ export class DurableInterpreter {
|
|
|
216
229
|
log.info('Starting OpenTelemetry SDK');
|
|
217
230
|
otelSDK.start();
|
|
218
231
|
}
|
|
232
|
+
else if (supervisorEnabled) {
|
|
233
|
+
otelSDK = new NodeSDK({
|
|
234
|
+
traceExporter: new Fake(),
|
|
235
|
+
serviceName: serviceName,
|
|
236
|
+
resource: resource,
|
|
237
|
+
});
|
|
238
|
+
log.info('Starting Testing OpenTelemetry SDK');
|
|
239
|
+
otelSDK.start();
|
|
240
|
+
}
|
|
219
241
|
const tracer = opentelemetry.trace.getTracer(serviceName, version);
|
|
220
242
|
const queueProvider = await QueueImpl.fromEnv(log);
|
|
221
243
|
const connectionFactory = DirectConnectionFactory.fromEnv(log);
|
|
@@ -223,14 +245,14 @@ export class DurableInterpreter {
|
|
|
223
245
|
if (options.contextProvider) {
|
|
224
246
|
// no need to set up a key-value provider if options.contextProvider is already
|
|
225
247
|
// initialised.
|
|
226
|
-
return new DurableInterpreter(log, compiler, options.contextProvider, express.Router(), express.Router(), new Map(), PlatformApiImpl.fromEnv(), connectionFactory, CronAPIClient.fromEnv(), tracer, issuesProvider, configReader, queueProvider, otelSDK);
|
|
248
|
+
return new DurableInterpreter(log, compiler, options.contextProvider, express.Router(), express.Router(), new Map(), new Map(), PlatformApiImpl.fromEnv(), connectionFactory, CronAPIClient.fromEnv(), tracer, issuesProvider, configReader, queueProvider, otelSDK);
|
|
227
249
|
}
|
|
228
|
-
const kvp = await getKVProvider(
|
|
250
|
+
const kvp = await getKVProvider();
|
|
229
251
|
const platformApi = PlatformApiImpl.fromEnv();
|
|
230
252
|
const organisationId = Deno.env.get(envVarOrgId) || 'development';
|
|
231
253
|
const environmentId = Deno.env.get(envVarEnvId) || 'development';
|
|
232
254
|
const ctxProvider = new ContextProviderImpl(log, kvp, new CredentialsProviderImpl(connectionFactory.credentials, connectionFactory.tokens, connectionFactory.oauth1, configReader, platformApi), platformApi, organisationId, environmentId, issuesProvider, queueProvider);
|
|
233
|
-
return new DurableInterpreter(log, compiler, ctxProvider, express.Router(), express.Router(), new Map(), PlatformApiImpl.fromEnv(), connectionFactory, CronAPIClient.fromEnv(), tracer, issuesProvider, configReader, queueProvider, otelSDK);
|
|
255
|
+
return new DurableInterpreter(log, compiler, ctxProvider, express.Router(), express.Router(), new Map(), new Map(), PlatformApiImpl.fromEnv(), connectionFactory, CronAPIClient.fromEnv(), tracer, issuesProvider, configReader, queueProvider, otelSDK);
|
|
234
256
|
}
|
|
235
257
|
register(workflow, options) {
|
|
236
258
|
const localAbortController = new AbortController();
|
|
@@ -250,6 +272,7 @@ export class DurableInterpreter {
|
|
|
250
272
|
tracer: this.tracer,
|
|
251
273
|
contextProvider: this.contextProvider,
|
|
252
274
|
webhookRouter: this.webhookRouter,
|
|
275
|
+
webhookRegistry: this.webhookRegistry,
|
|
253
276
|
queueProvider: this.queueProvider,
|
|
254
277
|
cronRouter: this.cronRouter,
|
|
255
278
|
cronRegistry: this.cronRegistry,
|
|
@@ -272,11 +295,14 @@ export class DurableInterpreter {
|
|
|
272
295
|
},
|
|
273
296
|
};
|
|
274
297
|
this.registeredWorkflows.push(registration);
|
|
298
|
+
if (supervisorEnabled) {
|
|
299
|
+
this.wfRegistration.push(registerWorkflow(workflow));
|
|
300
|
+
}
|
|
275
301
|
return registration;
|
|
276
302
|
}
|
|
277
|
-
start() {
|
|
278
|
-
const port = Deno.env.get(
|
|
279
|
-
const cronPort = Deno.env.get(
|
|
303
|
+
async start() {
|
|
304
|
+
const port = Deno.env.get(envPort) || 3000;
|
|
305
|
+
const cronPort = Deno.env.get(envCronPort) || 3001;
|
|
280
306
|
const webhookApp = express();
|
|
281
307
|
const cronApp = express();
|
|
282
308
|
cronApp.use(express.json());
|
|
@@ -303,11 +329,18 @@ export class DurableInterpreter {
|
|
|
303
329
|
triggerName: registration.triggerName,
|
|
304
330
|
error: err instanceof Error ? err.toString() : err,
|
|
305
331
|
});
|
|
332
|
+
this.tracer.startActiveSpan('done', (span) => {
|
|
333
|
+
span.setAttribute('error.message', err instanceof Error ? err.toString() : err);
|
|
334
|
+
span.setAttribute('execution.id', ctx.executionId);
|
|
335
|
+
span.setAttribute('result', 'fail');
|
|
336
|
+
span.setAttribute('workflow.id', ctx.workflowId || 'unknown-workflow');
|
|
337
|
+
span.end();
|
|
338
|
+
});
|
|
306
339
|
try {
|
|
307
340
|
ctx.options.onError?.(ctx.withData(err));
|
|
308
341
|
}
|
|
309
342
|
catch (err) {
|
|
310
|
-
ctx.log.error('DurableInterpreter.
|
|
343
|
+
ctx.log.error('DurableInterpreter.onError: failed to call onError handler', {
|
|
311
344
|
triggerName: registration.triggerName,
|
|
312
345
|
error: err instanceof Error ? err.toString() : err,
|
|
313
346
|
});
|
|
@@ -325,6 +358,12 @@ export class DurableInterpreter {
|
|
|
325
358
|
triggerName: registration.triggerName,
|
|
326
359
|
durationMs,
|
|
327
360
|
});
|
|
361
|
+
this.tracer.startActiveSpan('done', (span) => {
|
|
362
|
+
span.setAttribute('execution.id', ctx.executionId);
|
|
363
|
+
span.setAttribute('result', 'pass');
|
|
364
|
+
span.setAttribute('workflow.id', ctx.workflowId || 'unknown-workflow');
|
|
365
|
+
span.end();
|
|
366
|
+
});
|
|
328
367
|
try {
|
|
329
368
|
ctx.options.onSuccess?.(ctx);
|
|
330
369
|
}
|
|
@@ -386,6 +425,7 @@ export class DurableInterpreter {
|
|
|
386
425
|
if (this.cronServer) {
|
|
387
426
|
this.cronServer.close();
|
|
388
427
|
}
|
|
428
|
+
this.otelSDK?.shutdown();
|
|
389
429
|
// Remove all signal listeners
|
|
390
430
|
for (const registration of this.registeredWorkflows) {
|
|
391
431
|
Deno.removeSignalListener('SIGINT', registration.sigintListener);
|
|
@@ -402,6 +442,10 @@ export class DurableInterpreter {
|
|
|
402
442
|
}
|
|
403
443
|
};
|
|
404
444
|
Deno.addSignalListener('SIGINT', this.shutdownServer);
|
|
445
|
+
if (supervisorEnabled) {
|
|
446
|
+
await Promise.all(this.wfRegistration);
|
|
447
|
+
await signalReady();
|
|
448
|
+
}
|
|
405
449
|
return new Promise((resolve) => {
|
|
406
450
|
let serversClosed = 0;
|
|
407
451
|
const totalServers = [this.webhookServer, this.cronServer].filter(Boolean).length;
|
|
@@ -438,7 +482,7 @@ export class DurableInterpreter {
|
|
|
438
482
|
}
|
|
439
483
|
}
|
|
440
484
|
async function waitForReady(log) {
|
|
441
|
-
const readyCheckUrl = Deno.env.get(
|
|
485
|
+
const readyCheckUrl = Deno.env.get(envReadyCheckURL);
|
|
442
486
|
if (!readyCheckUrl) {
|
|
443
487
|
return Promise.resolve();
|
|
444
488
|
}
|
|
@@ -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,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAU7D,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG9F,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"ObservableCompiler.d.ts","sourceRoot":"","sources":["../../../../src/src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O,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,eAAe,CAAC,GAAG,EAAE,CAAC,CAAC;CAIjF"}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* As of the Change Date, in accordance with the Business Source License,
|
|
11
11
|
* use of this software will be governed by the Apache License, Version 2.0.
|
|
12
12
|
*/
|
|
13
|
-
import { envVarEnvId, envVarProjectId, envVarSDKApiBaseURL, } from '../../
|
|
13
|
+
import { envVarEnvId, envVarProjectId, envVarSDKApiBaseURL, } from '../../internal/constants.js';
|
|
14
14
|
import { ConsoleLogger } from '../../mod.js';
|
|
15
15
|
export class QueueImpl {
|
|
16
16
|
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"}
|
|
@@ -22,7 +22,9 @@ function compileCatch(compilerCtx, task) {
|
|
|
22
22
|
return compilerCtx.tracer.startActiveSpan(`catch`, (span) => {
|
|
23
23
|
span.setAttribute('execution.id', ctx.executionId);
|
|
24
24
|
span.setAttribute('task.type', 'catch');
|
|
25
|
+
span.setAttribute('type', 'task');
|
|
25
26
|
if (error instanceof Error) {
|
|
27
|
+
span.setAttribute('status', 'fail');
|
|
26
28
|
span.recordException(error);
|
|
27
29
|
span.setAttribute('error.message', error.message);
|
|
28
30
|
span.setAttribute('error.stack', error.stack ?? '');
|
|
@@ -60,7 +62,7 @@ function compileCatch(compilerCtx, task) {
|
|
|
60
62
|
reason: 'error',
|
|
61
63
|
severity: 'low',
|
|
62
64
|
});
|
|
63
|
-
span.setAttribute('
|
|
65
|
+
span.setAttribute('status', 'fail');
|
|
64
66
|
span.end();
|
|
65
67
|
return errorOperator(of(ctx.withData(new ExecutionError(ctx, `${error}`, { cause: error }), { recoveredFromCatch: true })));
|
|
66
68
|
});
|
|
@@ -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"}
|
|
@@ -10,20 +10,43 @@
|
|
|
10
10
|
* As of the Change Date, in accordance with the Business Source License,
|
|
11
11
|
* use of this software will be governed by the Apache License, Version 2.0.
|
|
12
12
|
*/
|
|
13
|
-
import { mergeMap
|
|
13
|
+
import { mergeMap } from 'rxjs';
|
|
14
14
|
import { FnTask } from '../../../dsl/tasks/FnTask.js';
|
|
15
|
+
import { sendTaskStartEvent, enabled as supervisorEnabled } from '../../../internal/supervisor.js';
|
|
15
16
|
function compileFn(compilerCtx, task) {
|
|
16
|
-
return (src) => src.pipe(
|
|
17
|
-
complete: () => compilerCtx.log.debug('fn.complete'),
|
|
18
|
-
}), mergeMap(async (ctx) => {
|
|
17
|
+
return (src) => src.pipe(mergeMap(async (ctx) => {
|
|
19
18
|
return await compilerCtx.tracer.startActiveSpan(`fn-${task.id}`, async (span) => {
|
|
19
|
+
await sendTaskStartEvent(task.id, ctx, span);
|
|
20
20
|
span.setAttribute('task.id', task.id);
|
|
21
|
+
span.setAttribute('type', 'task');
|
|
22
|
+
span.setAttribute('task.type', 'fn');
|
|
21
23
|
span.setAttribute('execution.id', ctx.executionId);
|
|
24
|
+
span.setAttribute('workflow.id', ctx.options.workflowId || 'unknown-workflow');
|
|
22
25
|
try {
|
|
26
|
+
const spanContext = span.spanContext();
|
|
27
|
+
const ctxWithLogger = ctx.withLogger(ctx.log.child({ spanId: spanContext.spanId, traceId: spanContext.traceId }));
|
|
28
|
+
let result;
|
|
23
29
|
if (typeof ctx.idx === 'number') {
|
|
24
|
-
|
|
30
|
+
result = ctx.withData(await task._fn(ctxWithLogger, ctx.idx));
|
|
25
31
|
}
|
|
26
|
-
|
|
32
|
+
else {
|
|
33
|
+
result = ctx.withData(await task._fn(ctxWithLogger));
|
|
34
|
+
}
|
|
35
|
+
if (supervisorEnabled) {
|
|
36
|
+
span.setAttribute('response.body', JSON.stringify(result.data));
|
|
37
|
+
}
|
|
38
|
+
span.setAttribute('status', 'pass');
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (error instanceof Error) {
|
|
43
|
+
span.setAttribute('status', 'fail');
|
|
44
|
+
span.recordException(error);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
span.recordException(new Error(String(error)));
|
|
48
|
+
}
|
|
49
|
+
throw error;
|
|
27
50
|
}
|
|
28
51
|
finally {
|
|
29
52
|
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"}
|