@versori/run 0.2.1 → 0.2.2-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/dsl/http/default.d.ts +2 -2
- package/esm/src/dsl/http/default.d.ts.map +1 -1
- package/esm/src/dsl/http/default.js +6 -5
- package/esm/src/dsl/http/types.d.ts +2 -2
- package/esm/src/dsl/http/types.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/constants.d.ts +2 -0
- package/esm/src/dsl/http/versori/constants.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/constants.js +2 -0
- package/esm/src/dsl/http/versori/contextcredentials.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/credentials/client.d.ts +1 -1
- package/esm/src/dsl/http/versori/credentials/client.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/credentials/client.js +4 -4
- package/esm/src/dsl/http/versori/roundtripper.d.ts +8 -6
- package/esm/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/roundtripper.js +123 -73
- package/esm/src/dsl/tasks/HttpTask.d.ts +1 -1
- package/esm/src/dsl/tasks/HttpTask.d.ts.map +1 -1
- package/esm/src/dsl/tasks/HttpTask.js +4 -2
- package/esm/src/interpreter/memory/MemoryInterpreter.d.ts +6 -2
- package/esm/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
- package/esm/src/interpreter/memory/MemoryInterpreter.js +68 -14
- package/esm/src/interpreter/memory/ObservableCompiler.d.ts +2 -0
- 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 +24 -7
- package/esm/src/interpreter/memory/compilers/fn.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/fn.js +12 -6
- package/esm/src/interpreter/memory/compilers/http.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/http.js +30 -6
- package/esm/src/interpreter/memory/compilers/parallel.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/schedule.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/schedule.js +29 -3
- package/esm/src/interpreter/memory/compilers/webhook.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/webhook.js +97 -68
- package/esm/src/observability/logging/ConsoleLogger.d.ts.map +1 -1
- package/package.json +5 -1
- package/script/src/dsl/http/default.d.ts +2 -2
- package/script/src/dsl/http/default.d.ts.map +1 -1
- package/script/src/dsl/http/default.js +6 -5
- package/script/src/dsl/http/types.d.ts +2 -2
- package/script/src/dsl/http/types.d.ts.map +1 -1
- package/script/src/dsl/http/versori/constants.d.ts +2 -0
- package/script/src/dsl/http/versori/constants.d.ts.map +1 -1
- package/script/src/dsl/http/versori/constants.js +3 -1
- package/script/src/dsl/http/versori/contextcredentials.d.ts.map +1 -1
- package/script/src/dsl/http/versori/credentials/client.d.ts +1 -1
- package/script/src/dsl/http/versori/credentials/client.d.ts.map +1 -1
- package/script/src/dsl/http/versori/credentials/client.js +3 -3
- package/script/src/dsl/http/versori/roundtripper.d.ts +8 -6
- package/script/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
- package/script/src/dsl/http/versori/roundtripper.js +123 -73
- package/script/src/dsl/tasks/HttpTask.d.ts +1 -1
- package/script/src/dsl/tasks/HttpTask.d.ts.map +1 -1
- package/script/src/dsl/tasks/HttpTask.js +4 -2
- package/script/src/interpreter/memory/MemoryInterpreter.d.ts +6 -2
- package/script/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
- package/script/src/interpreter/memory/MemoryInterpreter.js +68 -14
- package/script/src/interpreter/memory/ObservableCompiler.d.ts +2 -0
- 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 +24 -7
- package/script/src/interpreter/memory/compilers/fn.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/fn.js +12 -6
- package/script/src/interpreter/memory/compilers/http.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/http.js +30 -6
- package/script/src/interpreter/memory/compilers/parallel.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/schedule.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/schedule.js +29 -3
- package/script/src/interpreter/memory/compilers/webhook.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/webhook.js +97 -68
- package/script/src/observability/logging/ConsoleLogger.d.ts.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryInterpreter.d.ts","sourceRoot":"","sources":["../../../../src/src/interpreter/memory/MemoryInterpreter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MemoryInterpreter.d.ts","sourceRoot":"","sources":["../../../../src/src/interpreter/memory/MemoryInterpreter.ts"],"names":[],"mappings":"AAAA,OAAsB,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG3D,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAgB,EAAqB,MAAM,EAAE,MAAM,SAAS,CAAC;AAG7D,OAAO,EAA+B,UAAU,EAAM,YAAY,EAAO,MAAM,MAAM,CAAC;AACtF,OAAO,EAAE,eAAe,EAAuB,MAAM,kCAAkC,CAAC;AAExF,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAahG,OAAO,EAAE,QAAQ,EAAgB,MAAM,uBAAuB,CAAC;AAG/D,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEpE,OAAO,EAAE,MAAM,EAAE,MAAM,uCAAuC,CAAC;AAC/D,OAAO,EAAmB,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE9E,MAAM,MAAM,wBAAwB,GAAG;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,kBA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d,OAAO,CAAC,EAAE,OAAO,YAAA;WAWzB,WAAW,CAAC,OAAO,GAAE,wBAA6B,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAiF5F,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,wBAAwB;IA+C/D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAgKtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAO9B"}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import opentelemetry from '@opentelemetry/api';
|
|
2
|
+
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
|
|
3
|
+
import { resourceFromAttributes } from '@opentelemetry/resources';
|
|
4
|
+
import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
2
5
|
import express from 'express';
|
|
6
|
+
import xmlparser from 'express-xml-bodyparser';
|
|
3
7
|
import { catchError, EMPTY, mergeMap, of, tap } from 'rxjs';
|
|
4
8
|
import { ContextProviderImpl } from '../../context/ContextProvider.js';
|
|
5
9
|
import { DefaultRoundTripperFactory } from '../../dsl/http/default.js';
|
|
10
|
+
import { envVarEnvId, envVarEnvironmentName, envVarOrgId, envVarOrgSlug, envVarOtelTracesURL, envVarProjectId, envVarVersion, } from '../../dsl/http/versori/constants.js';
|
|
11
|
+
import { CronAPIClient } from '../../dsl/http/versori/cronapi.js';
|
|
6
12
|
import { PlatformAPIClient } from '../../dsl/http/versori/platformapi.js';
|
|
7
13
|
import { VersoriCredentialsFactory } from '../../dsl/http/versori/roundtripper.js';
|
|
8
14
|
import { WorkflowImpl } from '../../dsl/Workflow.js';
|
|
@@ -10,9 +16,8 @@ import { MemoryKeyValueProvider } from '../../kv/memory/MemoryKeyValueProvider.j
|
|
|
10
16
|
import { NatsKeyValueProvider } from '../../kv/nats/NatsKeyValueProvider.js';
|
|
11
17
|
import { ConsoleLogger } from '../../observability/logging/ConsoleLogger.js';
|
|
12
18
|
import { ObservableCompiler } from './ObservableCompiler.js';
|
|
13
|
-
import { CronAPIClient } from '../../dsl/http/versori/cronapi.js';
|
|
14
19
|
export class MemoryInterpreter {
|
|
15
|
-
constructor(log, compiler, contextProvider, roundTripperFactory, router, cronRegistry, connectionProvider, cronProvider) {
|
|
20
|
+
constructor(log, compiler, contextProvider, roundTripperFactory, router, cronRegistry, connectionProvider, cronProvider, tracer, otelSDK) {
|
|
16
21
|
Object.defineProperty(this, "log", {
|
|
17
22
|
enumerable: true,
|
|
18
23
|
configurable: true,
|
|
@@ -61,6 +66,18 @@ export class MemoryInterpreter {
|
|
|
61
66
|
writable: true,
|
|
62
67
|
value: cronProvider
|
|
63
68
|
});
|
|
69
|
+
Object.defineProperty(this, "tracer", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
configurable: true,
|
|
72
|
+
writable: true,
|
|
73
|
+
value: tracer
|
|
74
|
+
});
|
|
75
|
+
Object.defineProperty(this, "otelSDK", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
configurable: true,
|
|
78
|
+
writable: true,
|
|
79
|
+
value: otelSDK
|
|
80
|
+
});
|
|
64
81
|
Object.defineProperty(this, "registeredWorkflows", {
|
|
65
82
|
enumerable: true,
|
|
66
83
|
configurable: true,
|
|
@@ -86,7 +103,7 @@ export class MemoryInterpreter {
|
|
|
86
103
|
value: false
|
|
87
104
|
});
|
|
88
105
|
if (typeof this.log === 'undefined') {
|
|
89
|
-
// this captures the old way of instantiating the MemoryInterpreter and provides an
|
|
106
|
+
// this captures the old way of instantiating the MemoryInterpreter and provides an
|
|
90
107
|
// error message back to the user to let them know they should use the new way.
|
|
91
108
|
throw new Error('MemoryInterpreter should not be instantiated directly. Use MemoryInterpreter.newInstance() instead.');
|
|
92
109
|
}
|
|
@@ -94,18 +111,47 @@ export class MemoryInterpreter {
|
|
|
94
111
|
static async newInstance(options = {}) {
|
|
95
112
|
const log = options.logger || new ConsoleLogger('debug');
|
|
96
113
|
const compiler = options.compiler || new ObservableCompiler();
|
|
114
|
+
const serviceName = Deno.env.get(envVarProjectId) || 'example-service';
|
|
115
|
+
const environmentID = Deno.env.get(envVarEnvId) || 'development';
|
|
116
|
+
const version = Deno.env.get(envVarVersion) || '1.0.0';
|
|
117
|
+
const environment = Deno.env.get(envVarEnvironmentName) || 'development';
|
|
118
|
+
const orgId = Deno.env.get(envVarOrgId) || 'development';
|
|
119
|
+
const orgSlug = Deno.env.get(envVarOrgSlug) || 'development';
|
|
120
|
+
const otelTracesURL = Deno.env.get(envVarOtelTracesURL);
|
|
121
|
+
let otelSDK;
|
|
122
|
+
// Do NOT change those attributes, they are used by the API to filter on
|
|
123
|
+
const resource = resourceFromAttributes({
|
|
124
|
+
'service.id': serviceName,
|
|
125
|
+
'service.environment': environment,
|
|
126
|
+
'service.environment_id': environmentID,
|
|
127
|
+
'service.version': version,
|
|
128
|
+
'service.organisation_id': orgId,
|
|
129
|
+
'service.organisation_slug': orgSlug,
|
|
130
|
+
});
|
|
131
|
+
if (otelTracesURL && serviceName) {
|
|
132
|
+
otelSDK = new NodeSDK({
|
|
133
|
+
traceExporter: new OTLPTraceExporter({
|
|
134
|
+
url: otelTracesURL,
|
|
135
|
+
}),
|
|
136
|
+
serviceName: serviceName,
|
|
137
|
+
resource: resource,
|
|
138
|
+
});
|
|
139
|
+
log.info('Starting OpenTelemetry SDK');
|
|
140
|
+
otelSDK.start();
|
|
141
|
+
}
|
|
142
|
+
const tracer = opentelemetry.trace.getTracer(serviceName, version);
|
|
97
143
|
const roundTripperFactory = options.skipVersoriCredentials
|
|
98
144
|
? new DefaultRoundTripperFactory()
|
|
99
|
-
: VersoriCredentialsFactory.fromEnv(log);
|
|
145
|
+
: VersoriCredentialsFactory.fromEnv(log, tracer);
|
|
100
146
|
if (options.contextProvider) {
|
|
101
147
|
// no need to set up a key-value provider if options.contextProvider is already
|
|
102
148
|
// initialised.
|
|
103
|
-
return new MemoryInterpreter(log, compiler, options.contextProvider, roundTripperFactory, express.Router(), new Map(), PlatformAPIClient.fromEnv(), CronAPIClient.fromEnv());
|
|
149
|
+
return new MemoryInterpreter(log, compiler, options.contextProvider, roundTripperFactory, express.Router(), new Map(), PlatformAPIClient.fromEnv(), CronAPIClient.fromEnv(), tracer, otelSDK);
|
|
104
150
|
}
|
|
105
151
|
const kvp = await (options.skipVersoriCredentials
|
|
106
152
|
? new MemoryKeyValueProvider()
|
|
107
153
|
: NatsKeyValueProvider.fromEnv());
|
|
108
|
-
return new MemoryInterpreter(log, compiler, new ContextProviderImpl(log, kvp, roundTripperFactory.credentials()), roundTripperFactory, express.Router(), new Map(), PlatformAPIClient.fromEnv(), CronAPIClient.fromEnv());
|
|
154
|
+
return new MemoryInterpreter(log, compiler, new ContextProviderImpl(log, kvp, roundTripperFactory.credentials()), roundTripperFactory, express.Router(), new Map(), PlatformAPIClient.fromEnv(), CronAPIClient.fromEnv(), tracer, otelSDK);
|
|
109
155
|
}
|
|
110
156
|
register(workflow, options) {
|
|
111
157
|
const localAbortController = new AbortController();
|
|
@@ -119,11 +165,12 @@ export class MemoryInterpreter {
|
|
|
119
165
|
const compilerContext = {
|
|
120
166
|
compiler: this.compiler,
|
|
121
167
|
log: this.log,
|
|
168
|
+
tracer: this.tracer,
|
|
122
169
|
contextProvider: this.contextProvider,
|
|
123
170
|
roundTripperFactory: this.roundTripperFactory,
|
|
124
171
|
router: this.router,
|
|
125
172
|
cronRegistry: this.cronRegistry,
|
|
126
|
-
connectionProvider: this.connectionProvider
|
|
173
|
+
connectionProvider: this.connectionProvider,
|
|
127
174
|
};
|
|
128
175
|
const trigger$ = this.compiler.compileTrigger(compilerContext, workflow.trigger, combinedSignal);
|
|
129
176
|
const task$ = this.compiler.compileTask(compilerContext, workflow.task);
|
|
@@ -134,7 +181,7 @@ export class MemoryInterpreter {
|
|
|
134
181
|
sigintListener: () => {
|
|
135
182
|
this.log.info('Received SIGINT, shutting down workflow');
|
|
136
183
|
localAbortController.abort();
|
|
137
|
-
}
|
|
184
|
+
},
|
|
138
185
|
};
|
|
139
186
|
this.registeredWorkflows.push(registration);
|
|
140
187
|
return registration;
|
|
@@ -151,8 +198,8 @@ export class MemoryInterpreter {
|
|
|
151
198
|
};
|
|
152
199
|
app.use(xmlparser(xml2jsDefaults));
|
|
153
200
|
// Add health check route
|
|
154
|
-
this.router.get(
|
|
155
|
-
res.json({ status:
|
|
201
|
+
this.router.get('/health', (_req, res) => {
|
|
202
|
+
res.json({ status: 'healthy' });
|
|
156
203
|
});
|
|
157
204
|
// Add router to the application
|
|
158
205
|
app.use(this.router);
|
|
@@ -163,7 +210,9 @@ export class MemoryInterpreter {
|
|
|
163
210
|
.pipe(tap((ctx) => {
|
|
164
211
|
ctx.log.info('MemoryInterpreter.executionStarted', { data: ctx.data });
|
|
165
212
|
}), mergeMap((ctx) => of(ctx).pipe(registration.task$, catchError((err) => {
|
|
166
|
-
ctx.log.error('MemoryInterpreter.executionError', {
|
|
213
|
+
ctx.log.error('MemoryInterpreter.executionError', {
|
|
214
|
+
error: err instanceof Error ? err.toString() : err,
|
|
215
|
+
});
|
|
167
216
|
try {
|
|
168
217
|
ctx.options.onError?.(ctx.withData(err));
|
|
169
218
|
}
|
|
@@ -196,7 +245,9 @@ export class MemoryInterpreter {
|
|
|
196
245
|
this.contextProvider.destroy(ctx);
|
|
197
246
|
},
|
|
198
247
|
error: (err) => {
|
|
199
|
-
this.log.error('MemoryInterpreter.error', {
|
|
248
|
+
this.log.error('MemoryInterpreter.error', {
|
|
249
|
+
error: err instanceof Error ? err.toString() : err,
|
|
250
|
+
});
|
|
200
251
|
Deno.removeSignalListener('SIGINT', registration.sigintListener);
|
|
201
252
|
},
|
|
202
253
|
complete: () => {
|
|
@@ -212,7 +263,9 @@ export class MemoryInterpreter {
|
|
|
212
263
|
this.cronProvider.updateCrons(this.cronRegistry);
|
|
213
264
|
}
|
|
214
265
|
catch (err) {
|
|
215
|
-
this.log.error('MemoryInterpreter.updateCronsError', {
|
|
266
|
+
this.log.error('MemoryInterpreter.updateCronsError', {
|
|
267
|
+
error: err instanceof Error ? err.toString() : err,
|
|
268
|
+
});
|
|
216
269
|
throw new Error('Unable to register scheduler tasks with central cron provider');
|
|
217
270
|
}
|
|
218
271
|
this.server = app.listen(port, () => {
|
|
@@ -257,6 +310,7 @@ export class MemoryInterpreter {
|
|
|
257
310
|
});
|
|
258
311
|
}
|
|
259
312
|
async stop() {
|
|
313
|
+
this.otelSDK?.shutdown();
|
|
260
314
|
if (this.shutdownServer) {
|
|
261
315
|
this.shutdownServer();
|
|
262
316
|
}
|
|
@@ -7,9 +7,11 @@ import { ContextProvider } from '../../context/ContextProvider.js';
|
|
|
7
7
|
import { ContextImpl } from '../../context/Context.js';
|
|
8
8
|
import { ConnectionProvider, RoundTripperFactory } from '../../dsl/http/types.js';
|
|
9
9
|
import { Router } from 'express';
|
|
10
|
+
import { Tracer } from '@opentelemetry/api';
|
|
10
11
|
export type CompilerContext = {
|
|
11
12
|
compiler: ObservableCompiler;
|
|
12
13
|
log: Logger;
|
|
14
|
+
tracer: Tracer;
|
|
13
15
|
contextProvider: ContextProvider;
|
|
14
16
|
roundTripperFactory: RoundTripperFactory;
|
|
15
17
|
connectionProvider: ConnectionProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObservableCompiler.d.ts","sourceRoot":"","sources":["../../../../src/src/interpreter/memory/ObservableCompiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC;AACpD,OAAO,EAAE,IAAI,EAAY,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,uCAAuC,CAAC;AAO/D,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE9F,OAAO,EAAE,OAAO,EAAe,MAAM,sBAAsB,CAAC;AAG5D,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,E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E,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"catch.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/catch.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAG5D,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AAmDnE,eAAO,MAAM,aAAa,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,CAGrE,CAAC"}
|
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
import { catchError, mergeMap, of } from 'rxjs';
|
|
2
2
|
import { CatchTask } from '../../../dsl/tasks/CatchTask.js';
|
|
3
3
|
import { ExecutionError } from '../ExecutionError.js';
|
|
4
|
-
function compileCatch(
|
|
5
|
-
const baseOperator =
|
|
6
|
-
const errorOperator =
|
|
4
|
+
function compileCatch(compilerCtx, task) {
|
|
5
|
+
const baseOperator = compilerCtx.compiler.compileTask(compilerCtx, task._base);
|
|
6
|
+
const errorOperator = compilerCtx.compiler.compileTask(compilerCtx, task._errorHandler);
|
|
7
7
|
return (src) => src.pipe(mergeMap((ctx) => {
|
|
8
8
|
return baseOperator(of(ctx)).pipe(catchError((error) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
return compilerCtx.tracer.startActiveSpan(`catch`, (span) => {
|
|
10
|
+
span.setAttribute('execution.id', ctx.executionId);
|
|
11
|
+
span.setAttribute('task.type', 'catch');
|
|
12
|
+
if (error instanceof Error) {
|
|
13
|
+
span.recordException(error);
|
|
14
|
+
span.setAttribute('error.message', error.message);
|
|
15
|
+
span.setAttribute('error.stack', error.stack ?? '');
|
|
16
|
+
span.end();
|
|
17
|
+
ctx.log.error('execution has encountered an error', {
|
|
18
|
+
error: error.message,
|
|
19
|
+
stack: error.stack,
|
|
20
|
+
});
|
|
21
|
+
return errorOperator(of(ctx.withData(new ExecutionError(ctx, error.message, { cause: error }))));
|
|
22
|
+
}
|
|
23
|
+
ctx.log.error('execution has encountered an error', {
|
|
24
|
+
error: error,
|
|
25
|
+
});
|
|
26
|
+
span.setAttribute('error', `${error}`);
|
|
27
|
+
span.end();
|
|
28
|
+
return errorOperator(of(ctx.withData(new ExecutionError(ctx, `${error}`, { cause: error }))));
|
|
29
|
+
});
|
|
13
30
|
}));
|
|
14
31
|
}));
|
|
15
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fn.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/fn.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAEtD,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"fn.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/fn.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAEtD,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AA4BnE,eAAO,MAAM,UAAU,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAG/D,CAAC"}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { mergeMap, tap } from 'rxjs';
|
|
2
2
|
import { FnTask } from '../../../dsl/tasks/FnTask.js';
|
|
3
|
-
function compileFn(
|
|
3
|
+
function compileFn(compilerCtx, task) {
|
|
4
4
|
return (src) => src.pipe(tap({
|
|
5
|
-
complete: () =>
|
|
5
|
+
complete: () => compilerCtx.log.debug('fn.complete')
|
|
6
6
|
}), mergeMap(async (ctx) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
return await compilerCtx.tracer.startActiveSpan(`fn-${task.id}`, async (span) => {
|
|
8
|
+
span.setAttribute('task.id', task.id);
|
|
9
|
+
span.setAttribute('execution.id', ctx.executionId);
|
|
10
|
+
if (typeof ctx.idx === 'number') {
|
|
11
|
+
span.end();
|
|
12
|
+
return ctx.withData(await task._fn(ctx, ctx.idx));
|
|
13
|
+
}
|
|
14
|
+
span.end();
|
|
15
|
+
return ctx.withData(await task._fn(ctx));
|
|
16
|
+
});
|
|
11
17
|
}));
|
|
12
18
|
}
|
|
13
19
|
export const fnCompiler = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/http.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/http.ts"],"names":[],"mappings":"AAIA,OAAO,EAAmB,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAE/E,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AAyDnE,eAAO,MAAM,YAAY,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAG5E,CAAC"}
|
|
@@ -1,17 +1,41 @@
|
|
|
1
1
|
import { mergeMap } from 'rxjs';
|
|
2
2
|
import { tap } from 'rxjs/operators';
|
|
3
3
|
import { HttpContextImpl, HttpTaskImpl } from '../../../dsl/tasks/HttpTask.js';
|
|
4
|
-
function compileHttp(
|
|
5
|
-
const roundtripper =
|
|
6
|
-
const dynamicFetcher =
|
|
7
|
-
|
|
8
|
-
complete: () => ctx.log.debug('http.complete'),
|
|
9
|
-
}), mergeMap(async (ctx) => {
|
|
4
|
+
function compileHttp(compilerCtx, task) {
|
|
5
|
+
const roundtripper = compilerCtx.roundTripperFactory.create(task.opts.connection);
|
|
6
|
+
const dynamicFetcher = compilerCtx.roundTripperFactory.createDynamic(task.opts.connection);
|
|
7
|
+
async function http(ctx) {
|
|
10
8
|
const _fetch = await roundtripper;
|
|
11
9
|
const _dynamicFetcher = await dynamicFetcher;
|
|
12
10
|
const httpContext = new HttpContextImpl(ctx, {}, _fetch, _dynamicFetcher);
|
|
13
11
|
const result = await task.fn(httpContext);
|
|
14
12
|
return ctx.withData(result);
|
|
13
|
+
}
|
|
14
|
+
return (src) => src.pipe(tap({
|
|
15
|
+
complete: () => compilerCtx.log.debug('http.complete'),
|
|
16
|
+
}), mergeMap(async (ctx) => {
|
|
17
|
+
return compilerCtx.tracer.startActiveSpan(`http-${task.id}`, async (span) => {
|
|
18
|
+
span.setAttribute('task.id', task.id);
|
|
19
|
+
span.setAttribute('task.type', 'http');
|
|
20
|
+
span.setAttribute('execution.id', ctx.executionId);
|
|
21
|
+
span.setAttribute('connection.name', task.opts.connection);
|
|
22
|
+
try {
|
|
23
|
+
let result = await http(ctx);
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (error instanceof Error) {
|
|
28
|
+
span.recordException(error);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
span.recordException(new Error(String(error)));
|
|
32
|
+
}
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
span.end();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
15
39
|
}));
|
|
16
40
|
}
|
|
17
41
|
export const httpCompiler = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parallel.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/parallel.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAElE,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"parallel.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/parallel.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAElE,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AAqCnE,eAAO,MAAM,gBAAgB,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAGrF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/schedule.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/schedule.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAEzF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA0H7C,eAAO,MAAM,gBAAgB,EAAE,eAAe,CAAC,YAAY,EAAE,eAAe,CAG3E,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
|
+
import { envVarEnvId, envVarEnvironmentName, envVarOrgId, envVarProjectId, } from '../../../dsl/http/versori/constants.js';
|
|
2
3
|
import { ScheduleTrigger } from '../../../dsl/triggers/ScheduleTrigger.js';
|
|
3
4
|
function compileSchedule(ctx, trigger, signal) {
|
|
4
5
|
return new Observable((subscriber) => {
|
|
@@ -6,24 +7,33 @@ function compileSchedule(ctx, trigger, signal) {
|
|
|
6
7
|
if (!ctx.router) {
|
|
7
8
|
throw new Error('Router not available in compiler context');
|
|
8
9
|
}
|
|
10
|
+
const projectId = Deno.env.get(envVarProjectId) || 'example-service';
|
|
11
|
+
const environmentId = Deno.env.get(envVarEnvId) || 'example-environment';
|
|
12
|
+
const environmentName = Deno.env.get(envVarEnvironmentName) || 'example-environment';
|
|
13
|
+
const orgId = Deno.env.get(envVarOrgId) || 'example-org';
|
|
9
14
|
const client = ctx.connectionProvider;
|
|
10
15
|
ctx.cronRegistry.set(trigger.id, trigger.schedule);
|
|
11
|
-
|
|
16
|
+
async function handleSchedule(req, res, span) {
|
|
12
17
|
try {
|
|
13
18
|
if (trigger.activationPredicate === undefined) {
|
|
14
19
|
const executionCtx = ctx.contextProvider.create({}, undefined);
|
|
20
|
+
span.setAttribute('execution.id', executionCtx.executionId);
|
|
15
21
|
try {
|
|
16
22
|
subscriber.next(executionCtx);
|
|
17
23
|
}
|
|
18
24
|
catch (error) {
|
|
19
25
|
executionCtx.log.error('execution error inside schedule', { error });
|
|
20
26
|
}
|
|
21
|
-
res.status(200).json({
|
|
27
|
+
res.status(200).json({
|
|
28
|
+
status: 'triggered',
|
|
29
|
+
executionId: executionCtx.executionId,
|
|
30
|
+
});
|
|
22
31
|
return;
|
|
23
32
|
}
|
|
24
33
|
const activations = await client.listActivations();
|
|
25
34
|
if (!activations || activations.length === 0) {
|
|
26
35
|
const executionCtx = ctx.contextProvider.create({}, undefined);
|
|
36
|
+
span.setAttribute('execution.id', executionCtx.executionId);
|
|
27
37
|
executionCtx.log.info('no activations found, continuing');
|
|
28
38
|
try {
|
|
29
39
|
subscriber.next(executionCtx);
|
|
@@ -31,7 +41,10 @@ function compileSchedule(ctx, trigger, signal) {
|
|
|
31
41
|
catch (error) {
|
|
32
42
|
executionCtx.log.error('execution error inside schedule', { error });
|
|
33
43
|
}
|
|
34
|
-
res.status(200).json({
|
|
44
|
+
res.status(200).json({
|
|
45
|
+
status: 'triggered',
|
|
46
|
+
executionId: executionCtx.executionId,
|
|
47
|
+
});
|
|
35
48
|
return;
|
|
36
49
|
}
|
|
37
50
|
activations.forEach((activation) => {
|
|
@@ -50,6 +63,19 @@ function compileSchedule(ctx, trigger, signal) {
|
|
|
50
63
|
ctx.log.error('execution error inside schedule', { error });
|
|
51
64
|
res.status(500).json({ error: 'Failed to trigger schedule' });
|
|
52
65
|
}
|
|
66
|
+
}
|
|
67
|
+
ctx.router.post(`/cron/${trigger.id}`, async (req, res) => {
|
|
68
|
+
await ctx.tracer.startActiveSpan(`schedule-${trigger.id}`, async (span) => {
|
|
69
|
+
span.setAttribute('task.id', trigger.id);
|
|
70
|
+
span.setAttribute('task.type', 'schedule');
|
|
71
|
+
span.setAttribute('schedule', trigger.schedule);
|
|
72
|
+
span.setAttribute('project.id', projectId);
|
|
73
|
+
span.setAttribute('environment.id', environmentId);
|
|
74
|
+
span.setAttribute('environment.name', environmentName);
|
|
75
|
+
span.setAttribute('org.id', orgId);
|
|
76
|
+
await handleSchedule(req, res, span);
|
|
77
|
+
span.end();
|
|
78
|
+
});
|
|
53
79
|
});
|
|
54
80
|
function cleanup() {
|
|
55
81
|
ctx.log.debug('scheduler trigger stopped');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/webhook.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAEtF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAgD7C,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,WAAW,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/webhook.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAEtF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAgD7C,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,WAAW,EAAE,cAAc,CAyPxE,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// In src/interpreter/memory/compilers/webhook.ts
|
|
2
1
|
import cors from 'cors';
|
|
3
2
|
import { pipeline } from 'node:stream/promises';
|
|
4
3
|
import { Observable } from 'rxjs';
|
|
@@ -82,89 +81,119 @@ export const webhookCompiler = {
|
|
|
82
81
|
}
|
|
83
82
|
// endpoint for sans user because I'm not quite sure how the dynamic routing works
|
|
84
83
|
ctx.router.post(`/${trigger.id}`, (req, res) => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
84
|
+
ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, (span) => {
|
|
85
|
+
span.setAttribute('task.id', trigger.id);
|
|
86
|
+
span.setAttribute('task.type', 'webhook');
|
|
87
|
+
const executionCtx = ctx.contextProvider.create(req.body, ctxOptionsFn(res));
|
|
88
|
+
span.setAttribute('execution.id', executionCtx.executionId);
|
|
89
|
+
try {
|
|
90
|
+
subscriber.next(executionCtx);
|
|
91
|
+
if (isAsync) {
|
|
92
|
+
sendResponse(res, onSuccess(executionCtx));
|
|
93
|
+
}
|
|
90
94
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
catch (error) {
|
|
96
|
+
executionCtx.log.error('webhook execution error', {
|
|
97
|
+
error: JSON.stringify(error),
|
|
98
|
+
});
|
|
99
|
+
if (isAsync) {
|
|
100
|
+
sendResponse(res, onError(executionCtx.withData(error)));
|
|
101
|
+
}
|
|
98
102
|
}
|
|
99
|
-
|
|
103
|
+
finally {
|
|
104
|
+
span.end();
|
|
105
|
+
}
|
|
106
|
+
});
|
|
100
107
|
});
|
|
101
108
|
// this endpoint will trigger the workflow for each activation given by the external user ID
|
|
102
109
|
ctx.router.post(`/${trigger.id}/users/:userId`, async (req, res) => {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, async (span) => {
|
|
111
|
+
span.setAttribute('task.id', trigger.id);
|
|
112
|
+
span.setAttribute('task.type', 'webhook');
|
|
113
|
+
span.setAttribute('user.id', req.params.userId);
|
|
114
|
+
const userId = req.params.userId;
|
|
115
|
+
const activations = await ctx.connectionProvider.getUserActivations(userId);
|
|
116
|
+
if (!activations || activations.length === 0) {
|
|
117
|
+
res.status(404).json({
|
|
118
|
+
status: 'error',
|
|
119
|
+
message: `No activations found for user: ${userId}`,
|
|
120
|
+
});
|
|
121
|
+
span.setAttribute('error.message', `No activations found for user: ${userId}`);
|
|
122
|
+
span.setAttribute('http.status_code', '404');
|
|
123
|
+
span.end();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const executionCtx = ctx.contextProvider.create(req.body, ctxOptionsFn(res));
|
|
127
|
+
span.setAttribute('execution.id', executionCtx.executionId);
|
|
128
|
+
const errors = [];
|
|
129
|
+
activations.forEach((activation) => {
|
|
130
|
+
const activationCtx = executionCtx.withActivation(activation);
|
|
131
|
+
try {
|
|
132
|
+
subscriber.next(activationCtx);
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
activationCtx.log.error('webhook execution error', {
|
|
136
|
+
error: JSON.stringify(error),
|
|
137
|
+
});
|
|
138
|
+
errors.push({
|
|
139
|
+
activationId: activation.id,
|
|
140
|
+
error,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
109
143
|
});
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
144
|
+
if (isAsync) {
|
|
145
|
+
if (errors.length === 0) {
|
|
146
|
+
sendResponse(res, onSuccess(executionCtx));
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
sendResponse(res, onError(executionCtx.withData(errors)));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
span.end();
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
// this endpoint will trigger the workflow only for the activation given by its ID
|
|
156
|
+
ctx.router.post(`/${trigger.id}/activations/:activationId`, async (req, res) => {
|
|
157
|
+
await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, async (span) => {
|
|
158
|
+
span.setAttribute('task.id', trigger.id);
|
|
159
|
+
span.setAttribute('task.type', 'webhook');
|
|
160
|
+
span.setAttribute('activation.id', req.params.activationId);
|
|
161
|
+
const activationId = req.params.activationId;
|
|
162
|
+
const activation = await ctx.connectionProvider.getActivation(activationId);
|
|
163
|
+
if (!activation) {
|
|
164
|
+
// TODO report back actual errors
|
|
165
|
+
res.status(404).json({
|
|
166
|
+
status: 'error',
|
|
167
|
+
message: `No activation found for ID: ${activationId}`,
|
|
168
|
+
});
|
|
169
|
+
span.setAttribute('error.message', `No activation found for ID: ${activationId}`);
|
|
170
|
+
span.setAttribute('http.status_code', '404');
|
|
171
|
+
span.end();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const activationCtx = ctx.contextProvider.create(req.body, {
|
|
175
|
+
...ctxOptionsFn(res),
|
|
176
|
+
activation,
|
|
177
|
+
});
|
|
178
|
+
span.setAttribute('execution.id', activationCtx.executionId);
|
|
116
179
|
try {
|
|
117
180
|
subscriber.next(activationCtx);
|
|
181
|
+
if (isAsync) {
|
|
182
|
+
sendResponse(res, onSuccess(activationCtx));
|
|
183
|
+
}
|
|
118
184
|
}
|
|
119
185
|
catch (error) {
|
|
120
186
|
activationCtx.log.error('webhook execution error', {
|
|
121
187
|
error: JSON.stringify(error),
|
|
122
188
|
});
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
if (isAsync) {
|
|
130
|
-
if (errors.length === 0) {
|
|
131
|
-
sendResponse(res, onSuccess(executionCtx));
|
|
189
|
+
if (isAsync) {
|
|
190
|
+
sendResponse(res, onError(activationCtx.withData(error)));
|
|
191
|
+
}
|
|
132
192
|
}
|
|
133
|
-
|
|
134
|
-
|
|
193
|
+
finally {
|
|
194
|
+
span.end();
|
|
135
195
|
}
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
// this endpoint will trigger the workflow only for the activation given by its ID
|
|
139
|
-
ctx.router.post(`/${trigger.id}/activations/:activationId`, async (req, res) => {
|
|
140
|
-
const activationId = req.params.activationId;
|
|
141
|
-
const activation = await ctx.connectionProvider.getActivation(activationId);
|
|
142
|
-
if (!activation) {
|
|
143
|
-
// TODO report back actual errors
|
|
144
|
-
res.status(404).json({
|
|
145
|
-
status: 'error',
|
|
146
|
-
message: `No activation found for ID: ${activationId}`,
|
|
147
|
-
});
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
const activationCtx = ctx.contextProvider.create(req.body, {
|
|
151
|
-
...ctxOptionsFn(res),
|
|
152
|
-
activation,
|
|
153
196
|
});
|
|
154
|
-
try {
|
|
155
|
-
subscriber.next(activationCtx);
|
|
156
|
-
if (isAsync) {
|
|
157
|
-
sendResponse(res, onSuccess(activationCtx));
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
catch (error) {
|
|
161
|
-
activationCtx.log.error('webhook execution error', {
|
|
162
|
-
error: JSON.stringify(error),
|
|
163
|
-
});
|
|
164
|
-
if (isAsync) {
|
|
165
|
-
sendResponse(res, onError(activationCtx.withData(error)));
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
197
|
});
|
|
169
198
|
function cleanup() {
|
|
170
199
|
ctx.log.debug('webhook trigger stopped');
|