@versori/run 0.4.25 → 0.4.26
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/context/AsyncWorkflow.js +1 -1
- package/esm/src/context/Context.d.ts +8 -24
- package/esm/src/context/Context.d.ts.map +1 -1
- package/esm/src/context/Context.js +18 -5
- package/esm/src/context/ContextProvider.d.ts +2 -0
- package/esm/src/context/ContextProvider.d.ts.map +1 -1
- package/esm/src/context/ContextProvider.js +5 -2
- package/esm/src/context/WorkflowClient.d.ts +28 -0
- package/esm/src/context/WorkflowClient.d.ts.map +1 -0
- package/esm/src/context/WorkflowClient.js +108 -0
- package/esm/src/context/mod.d.ts +2 -1
- package/esm/src/context/mod.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/webhookmiddleware.d.ts +1 -1
- package/esm/src/dsl/http/versori/webhookmiddleware.d.ts.map +1 -1
- package/esm/src/dsl/tasks/HttpTask.d.ts +5 -3
- package/esm/src/dsl/tasks/HttpTask.d.ts.map +1 -1
- package/esm/src/dsl/tasks/HttpTask.js +3 -0
- package/esm/src/internal/InternalAuth.d.ts +0 -1
- package/esm/src/internal/InternalAuth.d.ts.map +1 -1
- package/esm/src/internal/InternalAuth.js +1 -17
- package/esm/src/interpreter/durable/DurableInterpreter.d.ts.map +1 -1
- package/esm/src/interpreter/durable/DurableInterpreter.js +4 -17
- package/esm/src/interpreter/durable/Queue.d.ts +25 -17
- package/esm/src/interpreter/durable/Queue.d.ts.map +1 -1
- package/esm/src/interpreter/durable/Queue.js +17 -8
- package/esm/src/interpreter/durable/compilers/catch.js +2 -2
- package/esm/src/interpreter/durable/compilers/durableworkflow.d.ts.map +1 -1
- package/esm/src/interpreter/durable/compilers/durableworkflow.js +31 -35
- package/esm/src/interpreter/memory/MemoryInterpreter.js +2 -2
- package/esm/src/interpreter/memory/compilers/catch.js +2 -2
- package/esm/src/kv/sdk/SDKKeyValue.d.ts +2 -2
- package/esm/src/kv/sdk/SDKKeyValue.d.ts.map +1 -1
- package/esm/src/kv/sdk/SDKKeyValue.js +9 -3
- package/package.json +1 -1
- package/script/src/context/AsyncWorkflow.js +1 -1
- package/script/src/context/Context.d.ts +8 -24
- package/script/src/context/Context.d.ts.map +1 -1
- package/script/src/context/Context.js +18 -5
- package/script/src/context/ContextProvider.d.ts +2 -0
- package/script/src/context/ContextProvider.d.ts.map +1 -1
- package/script/src/context/ContextProvider.js +5 -2
- package/script/src/context/WorkflowClient.d.ts +28 -0
- package/script/src/context/WorkflowClient.d.ts.map +1 -0
- package/script/src/context/WorkflowClient.js +112 -0
- package/script/src/context/mod.d.ts +2 -1
- package/script/src/context/mod.d.ts.map +1 -1
- package/script/src/dsl/http/versori/webhookmiddleware.d.ts +1 -1
- package/script/src/dsl/http/versori/webhookmiddleware.d.ts.map +1 -1
- package/script/src/dsl/tasks/HttpTask.d.ts +5 -3
- package/script/src/dsl/tasks/HttpTask.d.ts.map +1 -1
- package/script/src/dsl/tasks/HttpTask.js +3 -0
- package/script/src/internal/InternalAuth.d.ts +0 -1
- package/script/src/internal/InternalAuth.d.ts.map +1 -1
- package/script/src/internal/InternalAuth.js +0 -16
- package/script/src/interpreter/durable/DurableInterpreter.d.ts.map +1 -1
- package/script/src/interpreter/durable/DurableInterpreter.js +3 -16
- package/script/src/interpreter/durable/Queue.d.ts +25 -17
- package/script/src/interpreter/durable/Queue.d.ts.map +1 -1
- package/script/src/interpreter/durable/Queue.js +17 -8
- package/script/src/interpreter/durable/compilers/catch.js +2 -2
- package/script/src/interpreter/durable/compilers/durableworkflow.d.ts.map +1 -1
- package/script/src/interpreter/durable/compilers/durableworkflow.js +31 -35
- package/script/src/interpreter/memory/MemoryInterpreter.js +1 -1
- package/script/src/interpreter/memory/compilers/catch.js +2 -2
- package/script/src/kv/sdk/SDKKeyValue.d.ts +2 -2
- package/script/src/kv/sdk/SDKKeyValue.d.ts.map +1 -1
- package/script/src/kv/sdk/SDKKeyValue.js +9 -3
- package/esm/src/internal/cli.d.ts +0 -2
- package/esm/src/internal/cli.d.ts.map +0 -1
- package/esm/src/internal/cli.js +0 -32
- package/script/src/internal/cli.d.ts +0 -2
- package/script/src/internal/cli.d.ts.map +0 -1
- package/script/src/internal/cli.js +0 -35
|
@@ -1,26 +1,34 @@
|
|
|
1
|
-
import { Logger } from '
|
|
1
|
+
import { Logger } from '@versori/run/observability';
|
|
2
2
|
export type WorkflowMsgMetadata = {
|
|
3
3
|
parentWorkflowId?: string;
|
|
4
|
-
executionId
|
|
5
|
-
activationId
|
|
4
|
+
executionId: string;
|
|
5
|
+
activationId: string;
|
|
6
6
|
userId?: string;
|
|
7
7
|
};
|
|
8
8
|
export type Workflows = {
|
|
9
|
-
workflows:
|
|
9
|
+
workflows: Workflow[];
|
|
10
10
|
};
|
|
11
|
-
export type
|
|
12
|
-
id
|
|
13
|
-
projectId
|
|
14
|
-
environmentId
|
|
11
|
+
export type Workflow = {
|
|
12
|
+
id: string;
|
|
13
|
+
projectId: string;
|
|
14
|
+
environmentId: string;
|
|
15
15
|
group: string;
|
|
16
|
-
payload
|
|
16
|
+
payload: string;
|
|
17
17
|
output?: string;
|
|
18
18
|
status?: 'available' | 'locked' | 'completed' | 'failed';
|
|
19
|
-
attempt
|
|
19
|
+
attempt: number;
|
|
20
|
+
maxAttempts?: number;
|
|
21
|
+
timeout: string;
|
|
22
|
+
createdAt: string;
|
|
23
|
+
metadata: WorkflowMsgMetadata;
|
|
24
|
+
};
|
|
25
|
+
export type SubmitWorkflow = {
|
|
26
|
+
group: string;
|
|
27
|
+
payload: string;
|
|
20
28
|
maxAttempts?: number;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
29
|
+
metadata: WorkflowMsgMetadata;
|
|
30
|
+
projectId?: string;
|
|
31
|
+
environmentId?: string;
|
|
24
32
|
};
|
|
25
33
|
export type CompleteWorkflowRequest = {
|
|
26
34
|
id: string;
|
|
@@ -39,14 +47,14 @@ export type RescheduleWorkflowRequest = {
|
|
|
39
47
|
after: string;
|
|
40
48
|
};
|
|
41
49
|
export type SubmitWorkflowsRequest = {
|
|
42
|
-
workflows:
|
|
50
|
+
workflows: SubmitWorkflow[];
|
|
43
51
|
};
|
|
44
52
|
export interface QueueAPI {
|
|
45
53
|
complete(request: CompleteWorkflowRequest): Promise<void>;
|
|
46
54
|
submit(request: SubmitWorkflowsRequest): Promise<Workflows>;
|
|
47
55
|
fetchWorkflows(request: FetchWorkflowsRequest): Promise<Workflows | undefined>;
|
|
48
56
|
reschedule(request: RescheduleWorkflowRequest): Promise<void>;
|
|
49
|
-
|
|
57
|
+
getWorkflow(workflowId: string): Promise<Workflow>;
|
|
50
58
|
}
|
|
51
59
|
export declare class QueueImpl implements QueueAPI {
|
|
52
60
|
private baseUrl;
|
|
@@ -59,7 +67,7 @@ export declare class QueueImpl implements QueueAPI {
|
|
|
59
67
|
submit(request: SubmitWorkflowsRequest): Promise<Workflows>;
|
|
60
68
|
fetchWorkflows(request: FetchWorkflowsRequest): Promise<Workflows | undefined>;
|
|
61
69
|
reschedule(request: RescheduleWorkflowRequest): Promise<void>;
|
|
62
|
-
|
|
70
|
+
getWorkflow(workflowId: string): Promise<Workflow>;
|
|
63
71
|
}
|
|
64
72
|
export declare class MockQueue implements QueueAPI {
|
|
65
73
|
constructor();
|
|
@@ -67,6 +75,6 @@ export declare class MockQueue implements QueueAPI {
|
|
|
67
75
|
submit(_request: SubmitWorkflowsRequest): Promise<Workflows>;
|
|
68
76
|
fetchWorkflows(_request: FetchWorkflowsRequest): Promise<Workflows | undefined>;
|
|
69
77
|
reschedule(_request: RescheduleWorkflowRequest): Promise<void>;
|
|
70
|
-
|
|
78
|
+
getWorkflow(_workflowId: string): Promise<Workflow>;
|
|
71
79
|
}
|
|
72
80
|
//# sourceMappingURL=Queue.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Queue.d.ts","sourceRoot":"","sources":["../../../../src/src/interpreter/durable/Queue.ts"],"names":[],"mappings":"
|
|
1
|
+
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,MAAM,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,SAAS,CAAC;IA2B3D,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IA8C9E,UAAU,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;IAoB7D,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;CAc3D;AAGD,qBAAa,SAAU,YAAW,QAAQ;;IAGtC,QAAQ,CAAC,QAAQ,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;IAG1D,MAAM,CAAC,QAAQ,EAAE,sBAAsB,GAAG,OAAO,CAAC,SAAS,CAAC;IAG5D,cAAc,CAAC,QAAQ,EAAE,qBAAqB,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAG/E,UAAU,CAAC,QAAQ,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;IAG9D,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;CAGtD"}
|
|
@@ -44,7 +44,6 @@ export class QueueImpl {
|
|
|
44
44
|
this.environmentId = environmentId;
|
|
45
45
|
}
|
|
46
46
|
static fromEnv(log) {
|
|
47
|
-
// TODO make these environment variables configurable in constants/ts
|
|
48
47
|
const baseUrl = Deno.env.get(envVarSDKApiBaseURL);
|
|
49
48
|
const _log = log || new ConsoleLogger('debug');
|
|
50
49
|
const projectId = Deno.env.get(envVarProjectId) || 'default-project';
|
|
@@ -69,7 +68,7 @@ export class QueueImpl {
|
|
|
69
68
|
output: request.output,
|
|
70
69
|
status: request.status,
|
|
71
70
|
});
|
|
72
|
-
throw new Error(
|
|
71
|
+
throw new Error(await resp.text());
|
|
73
72
|
}
|
|
74
73
|
return;
|
|
75
74
|
}
|
|
@@ -107,16 +106,27 @@ export class QueueImpl {
|
|
|
107
106
|
}),
|
|
108
107
|
});
|
|
109
108
|
if (!resp.ok) {
|
|
110
|
-
|
|
109
|
+
let errorText = "";
|
|
110
|
+
try {
|
|
111
|
+
const vErr = (await resp.json());
|
|
112
|
+
errorText = vErr.message;
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
errorText = await resp.text();
|
|
116
|
+
}
|
|
111
117
|
this.log.error('Failed to fetch workflows', {
|
|
112
|
-
error: errorText
|
|
118
|
+
error: errorText,
|
|
113
119
|
ttl: request.ttl,
|
|
114
120
|
limit: request.limit,
|
|
115
121
|
group: request.group,
|
|
116
122
|
projectId: this.projectId || request.projectId,
|
|
123
|
+
response: {
|
|
124
|
+
status: resp.status,
|
|
125
|
+
statusText: resp.statusText,
|
|
126
|
+
},
|
|
117
127
|
});
|
|
118
128
|
throw new Error('failed to fetch workflows', {
|
|
119
|
-
cause: new Error(errorText
|
|
129
|
+
cause: new Error(errorText),
|
|
120
130
|
});
|
|
121
131
|
}
|
|
122
132
|
if (resp.status === 204) {
|
|
@@ -142,8 +152,7 @@ export class QueueImpl {
|
|
|
142
152
|
}
|
|
143
153
|
return;
|
|
144
154
|
}
|
|
145
|
-
async
|
|
146
|
-
// this endpoint returns a 404 if the workflow is not completed
|
|
155
|
+
async getWorkflow(workflowId) {
|
|
147
156
|
const resp = await fetch(`${this.baseUrl}/v1/workflows/fetch/${workflowId}`, {
|
|
148
157
|
method: 'GET',
|
|
149
158
|
});
|
|
@@ -170,7 +179,7 @@ export class MockQueue {
|
|
|
170
179
|
reschedule(_request) {
|
|
171
180
|
throw new Error('Method not implemented.');
|
|
172
181
|
}
|
|
173
|
-
|
|
182
|
+
getWorkflow(_workflowId) {
|
|
174
183
|
throw new Error('Method not implemented.');
|
|
175
184
|
}
|
|
176
185
|
}
|
|
@@ -35,7 +35,7 @@ function compileCatch(compilerCtx, task) {
|
|
|
35
35
|
annotations: {
|
|
36
36
|
'error': error.message,
|
|
37
37
|
'stack': error.stack || '',
|
|
38
|
-
'workflowId': ctx.options.
|
|
38
|
+
'workflowId': ctx.options.workflow?.id || ctx.workflow?.id || '',
|
|
39
39
|
'executionId': ctx.executionId,
|
|
40
40
|
'activationId': ctx.activation.id,
|
|
41
41
|
'activationExternalId': ctx.activation?.user.externalId,
|
|
@@ -52,7 +52,7 @@ function compileCatch(compilerCtx, task) {
|
|
|
52
52
|
annotations: {
|
|
53
53
|
'error': error.message,
|
|
54
54
|
'stack': error.stack || '',
|
|
55
|
-
'workflowId': ctx.options.
|
|
55
|
+
'workflowId': ctx.options.workflow?.id || ctx.workflow?.id || '',
|
|
56
56
|
'executionId': ctx.executionId,
|
|
57
57
|
'activationId': ctx.activation.id,
|
|
58
58
|
'activationExternalId': ctx.activation?.user.externalId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durableworkflow.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/durableworkflow.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"durableworkflow.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/durableworkflow.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAW,WAAW,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EACH,mBAAmB,EACnB,sBAAsB,EACzB,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,wBAAgB,sBAAsB,CAClC,GAAG,EAAE,sBAAsB,EAC3B,OAAO,EAAE,sBAAsB,EAC/B,MAAM,EAAE,WAAW,GACpB,UAAU,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC,CAyF9C;AAED,eAAO,MAAM,uBAAuB,EAAE,eAAe,CAAC,mBAAmB,EAAE,sBAAsB,CAIhG,CAAC"}
|
|
@@ -10,6 +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 { ulid } from '../../../../deps/jsr.io/@std/ulid/1.0.0/mod.js';
|
|
13
14
|
import { Observable } from 'rxjs';
|
|
14
15
|
import { DurableWorkflowTrigger, } from '../../../dsl/triggers/DurableTrigger.js';
|
|
15
16
|
import { envVarEnvId } from '../../../internal/constants.js';
|
|
@@ -21,20 +22,12 @@ export function compileDurableWorkflow(ctx, trigger, signal) {
|
|
|
21
22
|
}
|
|
22
23
|
signal.addEventListener('abort', cleanup, { once: true });
|
|
23
24
|
let consecutiveErrors = 0;
|
|
24
|
-
const maxConsecutiveErrors = 5;
|
|
25
25
|
(async () => {
|
|
26
26
|
while (true) {
|
|
27
27
|
if (signal.aborted) {
|
|
28
28
|
cleanup();
|
|
29
29
|
break;
|
|
30
30
|
}
|
|
31
|
-
if (consecutiveErrors >= maxConsecutiveErrors) {
|
|
32
|
-
ctx.log.error('reached too many consecutive errors stopping trigger', {
|
|
33
|
-
'triggerId': trigger.id,
|
|
34
|
-
});
|
|
35
|
-
cleanup();
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
31
|
try {
|
|
39
32
|
// Right now the API itself will hang for a period of time if no workflows are available.
|
|
40
33
|
// so we don't need to add a delay here.
|
|
@@ -47,37 +40,38 @@ export function compileDurableWorkflow(ctx, trigger, signal) {
|
|
|
47
40
|
continue;
|
|
48
41
|
}
|
|
49
42
|
for (const wf of wfs.workflows) {
|
|
50
|
-
if (wf.id &&
|
|
51
|
-
wf.attempt !== undefined &&
|
|
52
|
-
trigger.options.maxAttempts &&
|
|
53
|
-
wf.attempt > trigger.options.maxAttempts) {
|
|
54
|
-
ctx.log.error('Workflow exceeded max attempts failing', {
|
|
55
|
-
workflowId: wf.id,
|
|
56
|
-
attempts: wf.attempt,
|
|
57
|
-
});
|
|
58
|
-
await ctx.queueProvider.complete({
|
|
59
|
-
id: wf.id,
|
|
60
|
-
output: wf.output,
|
|
61
|
-
status: 'failed',
|
|
62
|
-
});
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
43
|
const data = JSON.parse(atob(wf.payload ?? '{}'));
|
|
66
44
|
let activation;
|
|
67
45
|
if (wf.metadata?.activationId) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
46
|
+
try {
|
|
47
|
+
const { data } = await ctx.platformApi.getActivation({
|
|
48
|
+
path: {
|
|
49
|
+
activation_id: wf.metadata.activationId,
|
|
50
|
+
organisation_id: ctx.organisationId,
|
|
51
|
+
environment_id: Deno.env.get(envVarEnvId) || 'development',
|
|
52
|
+
},
|
|
53
|
+
throwOnError: true,
|
|
54
|
+
});
|
|
55
|
+
activation = data;
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
ctx.log.error('Failed to get activation', { error });
|
|
59
|
+
throw new Error('Failed to get activation');
|
|
60
|
+
}
|
|
77
61
|
}
|
|
78
|
-
const newContext = ctx.contextProvider.
|
|
79
|
-
|
|
80
|
-
|
|
62
|
+
const newContext = ctx.contextProvider.createWithExecutionId(activation, data, wf.metadata?.executionId ?? ulid().toString(), {
|
|
63
|
+
workflow: wf,
|
|
64
|
+
onSuccess: (completedContext) => {
|
|
65
|
+
// locked status means we own the workflow and it's not completed yet
|
|
66
|
+
if (wf.status !== 'locked') {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
ctx.queueProvider.complete({
|
|
70
|
+
id: wf.id,
|
|
71
|
+
output: btoa(JSON.stringify(completedContext.data)),
|
|
72
|
+
status: 'completed',
|
|
73
|
+
});
|
|
74
|
+
},
|
|
81
75
|
});
|
|
82
76
|
consecutiveErrors = 0;
|
|
83
77
|
subscriber.next(newContext);
|
|
@@ -86,6 +80,8 @@ export function compileDurableWorkflow(ctx, trigger, signal) {
|
|
|
86
80
|
catch (error) {
|
|
87
81
|
ctx.log.error('Error fetching workflows', { error });
|
|
88
82
|
consecutiveErrors++;
|
|
83
|
+
// no workflows available, back-off a bit before retrying
|
|
84
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(consecutiveErrors * 1000, 30000)));
|
|
89
85
|
}
|
|
90
86
|
}
|
|
91
87
|
})();
|
|
@@ -22,7 +22,7 @@ import { ContextProviderImpl } from '../../context/ContextProvider.js';
|
|
|
22
22
|
import { VersoriConfigReader } from '../../dsl/http/versori/configloader.js';
|
|
23
23
|
import { CronAPIClient } from '../../dsl/http/versori/cronapi.js';
|
|
24
24
|
import { WorkflowImpl } from '../../dsl/Workflow.js';
|
|
25
|
-
import { envVarEnvId, envVarEnvironmentName, envVarLocalRun, envVarOrgId, envVarOrgSlug, envVarOtelTracesURL, envVarProjectId, envVarVersion } from '../../internal/constants.js';
|
|
25
|
+
import { envVarEnvId, envVarEnvironmentName, envVarLocalRun, envVarOrgId, envVarOrgSlug, envVarOtelTracesURL, envVarProjectId, envVarVersion, } from '../../internal/constants.js';
|
|
26
26
|
import { IssueImpl } from '../../issues/Issues.js';
|
|
27
27
|
import { MemoryKeyValueProvider } from '../../kv/memory/MemoryKeyValueProvider.js';
|
|
28
28
|
import { NatsKeyValueProvider } from '../../kv/nats/NatsKeyValueProvider.js';
|
|
@@ -273,7 +273,7 @@ export class MemoryInterpreter {
|
|
|
273
273
|
Deno.addSignalListener('SIGINT', registration.sigintListener);
|
|
274
274
|
registration.subscription = registration.trigger$
|
|
275
275
|
.pipe(tap((ctx) => {
|
|
276
|
-
ctx.log.info('MemoryInterpreter.executionStarted', {
|
|
276
|
+
ctx.log.info('MemoryInterpreter.executionStarted', {});
|
|
277
277
|
}), mergeMap((ctx) => of(ctx).pipe(registration.task$, catchError((err) => {
|
|
278
278
|
ctx.log.error('MemoryInterpreter.executionError', {
|
|
279
279
|
error: err instanceof Error ? err.toString() : err,
|
|
@@ -34,7 +34,7 @@ function compileCatch(compilerCtx, task) {
|
|
|
34
34
|
annotations: {
|
|
35
35
|
'error': error.message,
|
|
36
36
|
'stack': error.stack || '',
|
|
37
|
-
'workflowId': ctx.options.
|
|
37
|
+
'workflowId': ctx.options.workflow?.id || ctx.workflow?.id || '',
|
|
38
38
|
'executionId': ctx.executionId,
|
|
39
39
|
'activationId': ctx.activation.id,
|
|
40
40
|
'activationExternalId': ctx.activation?.user.externalId,
|
|
@@ -48,7 +48,7 @@ function compileCatch(compilerCtx, task) {
|
|
|
48
48
|
annotations: {
|
|
49
49
|
'error': error.message,
|
|
50
50
|
'stack': error.stack || '',
|
|
51
|
-
'workflowId': ctx.options.
|
|
51
|
+
'workflowId': ctx.options.workflow?.id || ctx.workflow?.id || '',
|
|
52
52
|
'executionId': ctx.executionId,
|
|
53
53
|
'activationId': ctx.activation.id,
|
|
54
54
|
'activationExternalId': ctx.activation?.user.externalId,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CountKVResponse } from '../../dsl/http/versori/kvapi/models/CountKVResponse.js';
|
|
2
2
|
import { CreateStoreResponse } from '../../dsl/http/versori/kvapi/models/CreateStoreResponse.js';
|
|
3
3
|
import { ListKVRequest } from '../../dsl/http/versori/kvapi/models/ListKVRequest.js';
|
|
4
4
|
import { ListKVResponse } from '../../dsl/http/versori/kvapi/models/ListKVResponse.js';
|
|
5
|
-
import {
|
|
5
|
+
import { GetOptions, KeyValue } from '../KeyValue.js';
|
|
6
6
|
export declare class SDKKeyValue implements KeyValue {
|
|
7
7
|
private readonly store;
|
|
8
8
|
private readonly prefix;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SDKKeyValue.d.ts","sourceRoot":"","sources":["../../../../src/src/kv/sdk/SDKKeyValue.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"SDKKeyValue.d.ts","sourceRoot":"","sources":["../../../../src/src/kv/sdk/SDKKeyValue.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,wDAAwD,CAAC;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,4DAA4D,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,MAAM,sDAAsD,CAAC;AACrF,OAAO,EAAE,cAAc,EAAE,MAAM,uDAAuD,CAAC;AAGvF,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEtD,qBAAa,WAAY,YAAW,QAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,KAAK;IAAuB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAnD,KAAK,EAAE,mBAAmB,EAAmB,MAAM,EAAE,MAAM;IAElF,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,GAAE,UAAU,CAAC,CAAC,CAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IA8BnF,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAUvD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ7C,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC;IAUjD,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IAY9E,OAAO,CAAC,WAAW;CAGtB"}
|
|
@@ -31,7 +31,13 @@ export class SDKKeyValue {
|
|
|
31
31
|
try {
|
|
32
32
|
const k = this.generateKey(key instanceof Array ? key.join('/') : key);
|
|
33
33
|
const entry = await KvOperationsService.getKv(this.store.id, k);
|
|
34
|
-
|
|
34
|
+
if (entry.value === undefined) {
|
|
35
|
+
if (options.throwOnNotFound) {
|
|
36
|
+
throw new Error('Key not found');
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
return JSON.parse(String(entry.value));
|
|
35
41
|
}
|
|
36
42
|
catch (error) {
|
|
37
43
|
if (options.throwOnNotFound && error instanceof Error &&
|
|
@@ -46,10 +52,10 @@ export class SDKKeyValue {
|
|
|
46
52
|
}
|
|
47
53
|
}
|
|
48
54
|
async set(key, value) {
|
|
49
|
-
|
|
55
|
+
const payload = JSON.stringify(value);
|
|
50
56
|
const k = this.generateKey(key instanceof Array ? key.join('/') : key);
|
|
51
57
|
await KvOperationsService.setKv(this.store.id, k, {
|
|
52
|
-
value:
|
|
58
|
+
value: payload,
|
|
53
59
|
options: {},
|
|
54
60
|
});
|
|
55
61
|
}
|
package/package.json
CHANGED
|
@@ -87,7 +87,7 @@ class AsyncWorkflow {
|
|
|
87
87
|
this.isWaiting = false;
|
|
88
88
|
throw new Error('wait timed out');
|
|
89
89
|
}
|
|
90
|
-
const workflow = await this.queue.
|
|
90
|
+
const workflow = await this.queue.getWorkflow(this.workflowId);
|
|
91
91
|
if (workflow.status === 'completed') {
|
|
92
92
|
// workflow is completed, parse the output and set the data and completed to true
|
|
93
93
|
const stringData = workflow.output;
|
|
@@ -1,40 +1,20 @@
|
|
|
1
1
|
import type * as express from 'express';
|
|
2
2
|
import { CredentialsProvider } from '../dsl/http/versori/contextcredentials.js';
|
|
3
|
-
import { QueueAPI } from '../interpreter/durable/Queue.js';
|
|
3
|
+
import { QueueAPI, Workflow } from '../interpreter/durable/Queue.js';
|
|
4
4
|
import { Issue, IssueAPI } from '../issues/Issues.js';
|
|
5
5
|
import { KeyValue, KeyValueProvider, KeyValueScope } from '../kv/KeyValue.js';
|
|
6
6
|
import { Logger } from '../observability/logging/Logger.js';
|
|
7
7
|
import { ActivationImpl } from './ActivationImpl.js';
|
|
8
8
|
import { AsyncWorkflow } from './AsyncWorkflow.js';
|
|
9
|
+
import { WorkflowInterface, WorkflowOpts } from './WorkflowClient.js';
|
|
9
10
|
export type OnSuccessFn = (ctx: Context<any>) => void;
|
|
10
11
|
export type OnErrorFn = (ctx: Context<any>) => void;
|
|
11
12
|
export type ContextOptions = {
|
|
12
|
-
|
|
13
|
+
workflow?: Workflow;
|
|
13
14
|
request?: express.Request;
|
|
14
15
|
onSuccess?: OnSuccessFn;
|
|
15
16
|
onError?: OnErrorFn;
|
|
16
17
|
};
|
|
17
|
-
/**
|
|
18
|
-
* WorkflowOpts is used to pass data to the workflow when starting it. Use either `data` or `dataRaw`, but not both.
|
|
19
|
-
*
|
|
20
|
-
* MaxAttempts is used to limit the number of attempts for the workflow execution.
|
|
21
|
-
*/
|
|
22
|
-
export type WorkflowOpts = {
|
|
23
|
-
/**
|
|
24
|
-
* MaxAttempts is used to limit the number of attempts for the workflow execution.
|
|
25
|
-
*
|
|
26
|
-
* @default 5
|
|
27
|
-
*/
|
|
28
|
-
maxAttempts?: number;
|
|
29
|
-
/**
|
|
30
|
-
* The data passed to the workflow instance when it was created.
|
|
31
|
-
*/
|
|
32
|
-
data?: unknown;
|
|
33
|
-
/**
|
|
34
|
-
* The data passed to the workflow instance when it was created, base64 encoded.
|
|
35
|
-
*/
|
|
36
|
-
dataRaw?: string;
|
|
37
|
-
};
|
|
38
18
|
/**
|
|
39
19
|
* CreateIssue is the payload for creating a new issue.
|
|
40
20
|
*/
|
|
@@ -66,6 +46,7 @@ export interface Context<D> {
|
|
|
66
46
|
readonly startTime: Date;
|
|
67
47
|
readonly data: D;
|
|
68
48
|
activation: ActivationImpl;
|
|
49
|
+
workflow?: Workflow;
|
|
69
50
|
/**
|
|
70
51
|
* Opens a key value store for the given scope, defaulting to ':project:' if not provided.
|
|
71
52
|
* @param scope The scope of the key value store to open, defaulting to ':project:' if not provided.
|
|
@@ -106,6 +87,7 @@ export interface Context<D> {
|
|
|
106
87
|
* Returns the underlying express {@link express.Request} object for the current execution.
|
|
107
88
|
*/
|
|
108
89
|
request(): express.Request | undefined;
|
|
90
|
+
workflowClient(): WorkflowInterface;
|
|
109
91
|
}
|
|
110
92
|
export declare class ContextImpl<D, Index = void> implements Context<D> {
|
|
111
93
|
#private;
|
|
@@ -119,14 +101,16 @@ export declare class ContextImpl<D, Index = void> implements Context<D> {
|
|
|
119
101
|
readonly options: ContextOptions;
|
|
120
102
|
constructor(log: Logger, kvp: KeyValueProvider, creds: CredentialsProvider, executionId: string, startTime: Date, data: D, activation: ActivationImpl, issues: IssueAPI, queue?: QueueAPI, options?: ContextOptions);
|
|
121
103
|
get activation(): ActivationImpl;
|
|
122
|
-
get
|
|
104
|
+
get workflow(): Workflow | undefined;
|
|
123
105
|
setIndex(idx: number): ContextImpl<D, number>;
|
|
124
106
|
withData<D2>(data: D2): ContextImpl<D2, Index>;
|
|
125
107
|
openKv(scope?: KeyValueScope): KeyValue;
|
|
126
108
|
request(): express.Request | undefined;
|
|
109
|
+
workflowClient(): WorkflowInterface;
|
|
127
110
|
start(group: string, opts: WorkflowOpts): Promise<AsyncWorkflow>;
|
|
128
111
|
createIssue(issue: CreateIssue, options?: {
|
|
129
112
|
deduplicate?: boolean;
|
|
113
|
+
duplicationKey?: string;
|
|
130
114
|
}): Promise<Issue | null>;
|
|
131
115
|
credentials(): CredentialsProvider;
|
|
132
116
|
destroy(scope: KeyValueScope): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../../src/src/context/Context.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../../src/src/context/Context.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,CAAC;AAExC,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC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EAAE,cAAc,EAC1B,MAAM,EAAE,QAAQ,EAChB,KAAK,CAAC,EAAE,QAAQ,EAChB,OAAO,GAAE,cAAmB;IA2BhC,IAAI,UAAU,IAAI,cAAc,CAE/B;IAED,IAAI,QAAQ,IAAI,QAAQ,GAAG,SAAS,CAEnC;IAED,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC;IAkB7C,QAAQ,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,GAAG,WAAW,CAAC,EAAE,EAAE,KAAK,CAAC;IAe9C,MAAM,CAAC,KAAK,GAAE,aAA2B,GAAG,QAAQ;IAepD,OAAO,IAAI,OAAO,CAAC,OAAO,GAAG,SAAS;IAItC,cAAc,IAAI,iBAAiB;IAQ7B,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAgCtE,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,OAAO,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;IAYpH,WAAW,IAAI,mBAAmB;IAUlC,OAAO,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAe5C,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAQlD"}
|
|
@@ -25,7 +25,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
25
25
|
var _ContextImpl_activation, _ContextImpl_issues, _ContextImpl_creds;
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
27
|
exports.ContextImpl = void 0;
|
|
28
|
+
const node_buffer_1 = require("node:buffer");
|
|
28
29
|
const AsyncWorkflow_js_1 = require("./AsyncWorkflow.js");
|
|
30
|
+
const WorkflowClient_js_1 = require("./WorkflowClient.js");
|
|
29
31
|
class ContextImpl {
|
|
30
32
|
constructor(log, kvp, creds, executionId, startTime, data, activation, issues, queue, options = {}) {
|
|
31
33
|
Object.defineProperty(this, "log", {
|
|
@@ -99,12 +101,13 @@ class ContextImpl {
|
|
|
99
101
|
this.request = this.request.bind(this);
|
|
100
102
|
this.createIssue = this.createIssue.bind(this);
|
|
101
103
|
this.destroy = this.destroy.bind(this);
|
|
104
|
+
this.workflowClient = this.workflowClient.bind(this);
|
|
102
105
|
}
|
|
103
106
|
get activation() {
|
|
104
107
|
return __classPrivateFieldGet(this, _ContextImpl_activation, "f");
|
|
105
108
|
}
|
|
106
|
-
get
|
|
107
|
-
return this.options.
|
|
109
|
+
get workflow() {
|
|
110
|
+
return this.options.workflow;
|
|
108
111
|
}
|
|
109
112
|
setIndex(idx) {
|
|
110
113
|
const next = new ContextImpl(this.log, this.kvp, __classPrivateFieldGet(this, _ContextImpl_creds, "f"), this.executionId, this.startTime, this.data, __classPrivateFieldGet(this, _ContextImpl_activation, "f"), __classPrivateFieldGet(this, _ContextImpl_issues, "f"), this.queue, this.options);
|
|
@@ -130,6 +133,12 @@ class ContextImpl {
|
|
|
130
133
|
request() {
|
|
131
134
|
return this.options.request;
|
|
132
135
|
}
|
|
136
|
+
workflowClient() {
|
|
137
|
+
if (!this.queue) {
|
|
138
|
+
throw new Error('Queue is not available for this context, cannot start workflow');
|
|
139
|
+
}
|
|
140
|
+
return new WorkflowClient_js_1.WorkflowImpl(this.queue, this.executionId, this.activation);
|
|
141
|
+
}
|
|
133
142
|
async start(group, opts) {
|
|
134
143
|
// this makes a post request to the endpoint sending a message and schedule the workflow to run
|
|
135
144
|
if (!this.queue) {
|
|
@@ -137,7 +146,7 @@ class ContextImpl {
|
|
|
137
146
|
}
|
|
138
147
|
let payload;
|
|
139
148
|
if (opts.data) {
|
|
140
|
-
payload = opts.data ?
|
|
149
|
+
payload = opts.data ? node_buffer_1.Buffer.from(JSON.stringify(opts.data)).toString('base64') : undefined;
|
|
141
150
|
}
|
|
142
151
|
else if (opts.dataRaw) {
|
|
143
152
|
payload = opts.dataRaw; // Assume this is already base64 encoded
|
|
@@ -151,7 +160,7 @@ class ContextImpl {
|
|
|
151
160
|
activationId: this.activation?.id,
|
|
152
161
|
userId: this.activation?.user?.externalId,
|
|
153
162
|
},
|
|
154
|
-
payload,
|
|
163
|
+
payload: payload ?? btoa("{}"),
|
|
155
164
|
maxAttempts: opts.maxAttempts,
|
|
156
165
|
},
|
|
157
166
|
],
|
|
@@ -159,10 +168,14 @@ class ContextImpl {
|
|
|
159
168
|
return new AsyncWorkflow_js_1.AsyncWorkflow(this.queue, resp.workflows[0].id ?? 'unknown');
|
|
160
169
|
}
|
|
161
170
|
createIssue(issue, options) {
|
|
171
|
+
// Default to deduplicate: true only if neither deduplicate nor duplicationKey are provided
|
|
172
|
+
const resolvedOptions = options?.deduplicate !== undefined || options?.duplicationKey !== undefined
|
|
173
|
+
? options
|
|
174
|
+
: { deduplicate: true, ...options };
|
|
162
175
|
return __classPrivateFieldGet(this, _ContextImpl_issues, "f").createIssue({
|
|
163
176
|
reason: 'manual',
|
|
164
177
|
...issue,
|
|
165
|
-
},
|
|
178
|
+
}, resolvedOptions);
|
|
166
179
|
}
|
|
167
180
|
credentials() {
|
|
168
181
|
return {
|
|
@@ -7,6 +7,7 @@ import { Context, ContextImpl, ContextOptions } from './Context.js';
|
|
|
7
7
|
import { Activation, PlatformApi } from '../services/platform/mod.js';
|
|
8
8
|
export interface ContextProvider {
|
|
9
9
|
create<D>(activation: Activation, data: D, options?: ContextOptions): ContextImpl<D, void>;
|
|
10
|
+
createWithExecutionId<D>(activation: Activation, data: D, executionId: string, options?: ContextOptions): ContextImpl<D, void>;
|
|
10
11
|
destroy(ctx: Context<any>): Promise<void>;
|
|
11
12
|
}
|
|
12
13
|
export declare class ContextProviderImpl implements ContextProvider {
|
|
@@ -19,6 +20,7 @@ export declare class ContextProviderImpl implements ContextProvider {
|
|
|
19
20
|
issues: IssueAPI;
|
|
20
21
|
queue?: QueueAPI;
|
|
21
22
|
constructor(log: Logger, kvp: KeyValueProvider, creds: CredentialsProvider, platformApi: PlatformApi, organisationId: string, environmentId: string, issues: IssueAPI, queue?: QueueAPI | undefined);
|
|
23
|
+
createWithExecutionId<D>(activation: Activation, data: D, executionId: string, options?: ContextOptions): ContextImpl<D, void>;
|
|
22
24
|
create<D>(activation: Activation, data: D, options?: ContextOptions): ContextImpl<D>;
|
|
23
25
|
destroy(_: Context<any>): Promise<void>;
|
|
24
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextProvider.d.ts","sourceRoot":"","sources":["../../../src/src/context/ContextProvider.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAGtE,MAAM,WAAW,eAAe;IAC5B,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,WAAW,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IAC3F,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7C;AAED,qBAAa,mBAAoB,YAAW,eAAe;IAWnD,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,Q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|
|
|
72
72
|
this.issues = issues;
|
|
73
73
|
this.queue = queue;
|
|
74
74
|
}
|
|
75
|
-
|
|
76
|
-
const executionId = (0, mod_js_1.ulid)();
|
|
75
|
+
createWithExecutionId(activation, data, executionId, options = {}) {
|
|
77
76
|
const logger = this.log.child({
|
|
78
77
|
executionId,
|
|
79
78
|
activationId: activation.id,
|
|
@@ -82,6 +81,10 @@ class ContextProviderImpl {
|
|
|
82
81
|
const activationImpl = new ActivationImpl_js_1.ActivationImpl(activation, this.platformApi, this.organisationId, this.environmentId, logger);
|
|
83
82
|
return new Context_js_1.ContextImpl(logger, this.kvp, this.creds, executionId, new Date(), data, activationImpl, this.issues, this.queue, options);
|
|
84
83
|
}
|
|
84
|
+
create(activation, data, options = {}) {
|
|
85
|
+
const executionId = (0, mod_js_1.ulid)();
|
|
86
|
+
return this.createWithExecutionId(activation, data, executionId, options);
|
|
87
|
+
}
|
|
85
88
|
destroy(_) {
|
|
86
89
|
return Promise.resolve();
|
|
87
90
|
}
|