@versori/run 0.5.0-alpha.4 → 0.5.0-alpha.6
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/FetchBuilder.d.ts.map +1 -1
- package/esm/src/connection/internal/FetchBuilder.js +11 -5
- package/esm/src/internal/InternalAuth.d.ts.map +1 -1
- package/esm/src/internal/InternalAuth.js +0 -1
- package/esm/src/internal/supervisor.d.ts.map +1 -1
- package/esm/src/internal/supervisor.js +52 -24
- package/esm/src/interpreter/durable/compilers/fn.d.ts.map +1 -1
- package/esm/src/interpreter/durable/compilers/fn.js +3 -5
- package/esm/src/interpreter/durable/compilers/http.d.ts.map +1 -1
- package/esm/src/interpreter/durable/compilers/http.js +2 -5
- package/esm/src/interpreter/memory/compilers/fn.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/fn.js +2 -4
- package/esm/src/interpreter/memory/compilers/http.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/http.js +1 -4
- package/esm/src/interpreter/memory/compilers/schedule.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/schedule.js +54 -1
- package/package.json +1 -1
- package/script/src/connection/internal/FetchBuilder.d.ts.map +1 -1
- package/script/src/connection/internal/FetchBuilder.js +11 -5
- package/script/src/internal/InternalAuth.d.ts.map +1 -1
- package/script/src/internal/InternalAuth.js +0 -1
- package/script/src/internal/supervisor.d.ts.map +1 -1
- package/script/src/internal/supervisor.js +52 -24
- package/script/src/interpreter/durable/compilers/fn.d.ts.map +1 -1
- package/script/src/interpreter/durable/compilers/fn.js +2 -4
- package/script/src/interpreter/durable/compilers/http.d.ts.map +1 -1
- package/script/src/interpreter/durable/compilers/http.js +2 -5
- package/script/src/interpreter/memory/compilers/fn.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/fn.js +1 -3
- package/script/src/interpreter/memory/compilers/http.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/http.js +1 -4
- package/script/src/interpreter/memory/compilers/schedule.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/schedule.js +54 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FetchBuilder.d.ts","sourceRoot":"","sources":["../../../../src/src/connection/internal/FetchBuilder.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE5D,MAAM,MAAM,eAAe,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB,
|
|
1
|
+
{"version":3,"file":"FetchBuilder.d.ts","sourceRoot":"","sources":["../../../../src/src/connection/internal/FetchBuilder.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE5D,MAAM,MAAM,eAAe,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;GAIG;AACH,qBAAa,YAAY;;IACrB,WAAW,EAAE,kBAAkB,EAAE,CAAC;gBAMtB,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,eAAe;IAelD,GAAG,CAAC,EAAE,EAAE,kBAAkB;IAI1B,KAAK,IAAI,SAAS;IAYlB,oBAAoB,IAAI,SAAS;IAOjC,OAAO,CAAC,eAAe;IAevB,OAAO,CAAC,eAAe;CAyF1B"}
|
|
@@ -70,7 +70,7 @@ export class FetchBuilder {
|
|
|
70
70
|
}
|
|
71
71
|
// during testing the user can choose to use a real connection or AI mock.
|
|
72
72
|
// so in supervised mode this function is used instead of the normal build() function.
|
|
73
|
-
// and it will make the
|
|
73
|
+
// and it will make the decision on using mock or real at runtime at the cost of performance
|
|
74
74
|
supervisedFetch() {
|
|
75
75
|
return (input, init) => {
|
|
76
76
|
let fetch = (input, init) => {
|
|
@@ -96,19 +96,25 @@ export class FetchBuilder {
|
|
|
96
96
|
span.setAttribute('connection.id', connectionId);
|
|
97
97
|
span.setAttribute('connection.name', connectionName);
|
|
98
98
|
span.setAttribute('isConnected', connectionId !== '');
|
|
99
|
-
if (init?.method) {
|
|
100
|
-
span.setAttribute('http.method', init.method);
|
|
101
|
-
}
|
|
102
99
|
try {
|
|
103
100
|
const response = await fetch(input, init);
|
|
104
101
|
if (supervisorEnabled) {
|
|
102
|
+
if (init?.method) {
|
|
103
|
+
span.setAttribute('http.method', init.method);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
span.setAttribute('http.method', 'GET');
|
|
107
|
+
}
|
|
105
108
|
// when we are in supervisor mode, we need to store the response body in the span attribute
|
|
106
109
|
// this will be shown the end-user in some UI in the future(the future is now)
|
|
107
110
|
const body = await response.clone().arrayBuffer();
|
|
108
111
|
// if response is text/* or json we store the body as a string, otherwise we store it as a base64 string
|
|
109
112
|
const contentType = response.headers.get('Content-Type');
|
|
110
113
|
span.setAttribute('response.content_type', contentType || '');
|
|
111
|
-
|
|
114
|
+
span.setAttribute('request.headers', JSON.stringify(init?.headers || {}));
|
|
115
|
+
if (contentType &&
|
|
116
|
+
(contentType.startsWith('text/') ||
|
|
117
|
+
contentType.startsWith('application/json'))) {
|
|
112
118
|
span.setAttribute('response.body', new TextDecoder().decode(body));
|
|
113
119
|
}
|
|
114
120
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InternalAuth.d.ts","sourceRoot":"","sources":["../../../src/src/internal/InternalAuth.ts"],"names":[],"mappings":"AAoBA,KAAK,kBAAkB,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAEpD,qBAAa,YAAY;IACrB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,aAAa,CAAS;IAE9B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,SAAS,CAAS;;
|
|
1
|
+
{"version":3,"file":"InternalAuth.d.ts","sourceRoot":"","sources":["../../../src/src/internal/InternalAuth.ts"],"names":[],"mappings":"AAoBA,KAAK,kBAAkB,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAEpD,qBAAa,YAAY;IACrB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,aAAa,CAAS;IAE9B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,SAAS,CAAS;;IAyBpB,aAAa,IAAI,OAAO,CAAC,kBAAkB,CAAC;CAsBrD"}
|
|
@@ -51,7 +51,6 @@ export class InternalAuth {
|
|
|
51
51
|
if (Deno.env.get(envVarInternalToken)) {
|
|
52
52
|
this.accessToken = Deno.env.get(envVarInternalToken) || '';
|
|
53
53
|
this.expiresAt = Date.now() + 365 * 24 * 60 * 60 * 1000; // expires in 1 year
|
|
54
|
-
console.log(`Using static token provided by ${envVarInternalToken}`);
|
|
55
54
|
return;
|
|
56
55
|
}
|
|
57
56
|
if (!this.clientId || !this.clientSecret || !this.tokenEndpoint) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supervisor.d.ts","sourceRoot":"","sources":["../../../src/src/internal/supervisor.ts"],"names":[],"mappings":"AAaA,OAAO,EACH,YAAY,EAIf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE3E,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"supervisor.d.ts","sourceRoot":"","sources":["../../../src/src/internal/supervisor.ts"],"names":[],"mappings":"AAaA,OAAO,EACH,YAAY,EAIf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE3E,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AA2ClD,eAAO,MAAM,OAAO,SAEhB,CAAC;AA2BL,KAAK,cAAc,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AA0DF,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAYjD;AAED,wBAAsB,gBAAgB,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CA0BxF;AAED,wBAAsB,kBAAkB,CAAC,CAAC,EAAE,CAAC,EACzC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EACtB,IAAI,EAAE,IAAI,GACX,OAAO,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAwC5B;AAED,wBAAsB,cAAc,CAChC,IAAI,EAAE,WAAW,GAAG,GAAG,EACvB,GAAG,CAAC,EAAE,cAAc,EACpB,OAAO,CAAC,EAAE,WAAW,GACtB,OAAO,CAAC,QAAQ,CAAC,CAoCnB;AA0BD,qBAAa,IAAK,YAAW,YAAY;;IAOrC,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE,cAAc,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,GAAG,IAAI;IAmBnF,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAIzB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAG9B"}
|
|
@@ -17,6 +17,11 @@ import { ScheduleTrigger } from '../dsl/triggers/ScheduleTrigger.js';
|
|
|
17
17
|
import { WebhookTrigger } from '../dsl/triggers/WebhookTrigger.js';
|
|
18
18
|
import { DurableWorkflowTrigger } from '../dsl/triggers/DurableTrigger.js';
|
|
19
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';
|
|
20
25
|
const supervisorURL = (function () {
|
|
21
26
|
return Deno.env.get('RUN_SUPERVISOR_URL') || '';
|
|
22
27
|
})();
|
|
@@ -33,7 +38,7 @@ const flows = (function () {
|
|
|
33
38
|
nodes[node.id] = {
|
|
34
39
|
description: node?.data?.description,
|
|
35
40
|
steps: node?.data?.steps,
|
|
36
|
-
files: node?.data?.files[0]
|
|
41
|
+
files: node?.data?.files[0],
|
|
37
42
|
};
|
|
38
43
|
}
|
|
39
44
|
return nodes;
|
|
@@ -67,13 +72,40 @@ function getTriggerData(workflow) {
|
|
|
67
72
|
return null;
|
|
68
73
|
}
|
|
69
74
|
function getTaskData(task) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
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;
|
|
77
109
|
}
|
|
78
110
|
export async function signalReady() {
|
|
79
111
|
if (!enabled) {
|
|
@@ -92,19 +124,15 @@ export async function registerWorkflow(workflow) {
|
|
|
92
124
|
if (!enabled) {
|
|
93
125
|
return;
|
|
94
126
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
trigger: triggerData,
|
|
105
|
-
tasks,
|
|
106
|
-
};
|
|
107
|
-
try {
|
|
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
|
+
};
|
|
108
136
|
await fetch(`${supervisorURL}/register-workflow`, {
|
|
109
137
|
method: 'POST',
|
|
110
138
|
body: JSON.stringify(data),
|
|
@@ -113,9 +141,9 @@ export async function registerWorkflow(workflow) {
|
|
|
113
141
|
},
|
|
114
142
|
});
|
|
115
143
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
logger.error('Failed to register workflow with supervisor', { error: err });
|
|
119
147
|
}
|
|
120
148
|
}
|
|
121
149
|
export async function sendTaskStartEvent(taskId, ctx, span) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fn.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/fn.ts"],"names":[],"mappings":"AA+BA,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAGtD,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"fn.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/fn.ts"],"names":[],"mappings":"AA+BA,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,15 +10,13 @@
|
|
|
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
15
|
import { sendTaskStartEvent, enabled as supervisorEnabled } from '../../../internal/supervisor.js';
|
|
16
16
|
function compileFn(compilerCtx, task) {
|
|
17
|
-
return (src) => src.pipe(
|
|
18
|
-
complete: () => compilerCtx.log.debug('fn.complete'),
|
|
19
|
-
}), mergeMap(async (ctx) => {
|
|
17
|
+
return (src) => src.pipe(mergeMap(async (ctx) => {
|
|
20
18
|
return await compilerCtx.tracer.startActiveSpan(`fn-${task.id}`, async (span) => {
|
|
21
|
-
await sendTaskStartEvent(task.id, span);
|
|
19
|
+
await sendTaskStartEvent(task.id, ctx, span);
|
|
22
20
|
span.setAttribute('task.id', task.id);
|
|
23
21
|
span.setAttribute('type', 'task');
|
|
24
22
|
span.setAttribute('task.type', 'fn');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/http.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAmB,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAG/E,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/http.ts"],"names":[],"mappings":"AAqBA,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"}
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
* use of this software will be governed by the Apache License, Version 2.0.
|
|
12
12
|
*/
|
|
13
13
|
import { mergeMap } from 'rxjs';
|
|
14
|
-
import { tap } from 'rxjs/operators';
|
|
15
14
|
import { DynamicFetchFactory } from '../../../connection/DynamicFetchFactory.js';
|
|
16
15
|
import { FetchBuilder } from '../../../connection/internal/FetchBuilder.js';
|
|
17
16
|
import { StaticFetchFactory } from '../../../connection/StaticFetchFactory.js';
|
|
@@ -69,11 +68,9 @@ function compileHttp(compilerCtx, task) {
|
|
|
69
68
|
const result = await task.fn(httpContext);
|
|
70
69
|
return ctx.withData(result);
|
|
71
70
|
}
|
|
72
|
-
return (src) => src.pipe(
|
|
73
|
-
complete: () => compilerCtx.log.debug('http.complete'),
|
|
74
|
-
}), mergeMap((ctx) => {
|
|
71
|
+
return (src) => src.pipe(mergeMap((ctx) => {
|
|
75
72
|
return compilerCtx.tracer.startActiveSpan(`http-${task.id}`, async (span) => {
|
|
76
|
-
await sendTaskStartEvent(task.id, span);
|
|
73
|
+
await sendTaskStartEvent(task.id, ctx, span);
|
|
77
74
|
span.setAttribute('task.id', task.id);
|
|
78
75
|
span.setAttribute('task.type', 'http');
|
|
79
76
|
span.setAttribute('type', 'task');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fn.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/fn.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAGtD,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":"AAgBA,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"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { mergeMap
|
|
1
|
+
import { mergeMap } from 'rxjs';
|
|
2
2
|
import { FnTask } from '../../../dsl/tasks/FnTask.js';
|
|
3
3
|
import { sendTaskStartEvent, enabled as supervisorEnabled } from '../../../internal/supervisor.js';
|
|
4
4
|
function compileFn(compilerCtx, task) {
|
|
5
|
-
return (src) => src.pipe(
|
|
6
|
-
complete: () => compilerCtx.log.debug('fn.complete'),
|
|
7
|
-
}), mergeMap(async (ctx) => {
|
|
5
|
+
return (src) => src.pipe(mergeMap(async (ctx) => {
|
|
8
6
|
return await compilerCtx.tracer.startActiveSpan(`fn-${task.id}`, async (span) => {
|
|
9
7
|
ctx = await sendTaskStartEvent(task.id, ctx, span);
|
|
10
8
|
span.setAttribute('task.id', task.id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/http.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAmB,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAG/E,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/http.ts"],"names":[],"mappings":"AAqBA,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"}
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
* use of this software will be governed by the Apache License, Version 2.0.
|
|
12
12
|
*/
|
|
13
13
|
import { mergeMap } from 'rxjs';
|
|
14
|
-
import { tap } from 'rxjs/operators';
|
|
15
14
|
import { DynamicFetchFactory } from '../../../connection/DynamicFetchFactory.js';
|
|
16
15
|
import { FetchBuilder } from '../../../connection/internal/FetchBuilder.js';
|
|
17
16
|
import { StaticFetchFactory } from '../../../connection/StaticFetchFactory.js';
|
|
@@ -69,9 +68,7 @@ function compileHttp(compilerCtx, task) {
|
|
|
69
68
|
const result = await task.fn(httpContext);
|
|
70
69
|
return ctx.withData(result);
|
|
71
70
|
}
|
|
72
|
-
return (src) => src.pipe(
|
|
73
|
-
complete: () => compilerCtx.log.debug('http.complete'),
|
|
74
|
-
}), mergeMap((ctx) => {
|
|
71
|
+
return (src) => src.pipe(mergeMap((ctx) => {
|
|
75
72
|
return compilerCtx.tracer.startActiveSpan(`http-${task.id}`, async (span) => {
|
|
76
73
|
ctx = await sendTaskStartEvent(task.id, ctx, span);
|
|
77
74
|
span.setAttribute('task.id', task.id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/schedule.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;
|
|
1
|
+
{"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/schedule.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AASzF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA8M7C,eAAO,MAAM,gBAAgB,EAAE,eAAe,CAAC,YAAY,EAAE,eAAe,CAG3E,CAAC"}
|
|
@@ -26,8 +26,43 @@ function compileSchedule(ctx, trigger, signal) {
|
|
|
26
26
|
const orgId = Deno.env.get(envVarOrgId) || 'example-org';
|
|
27
27
|
const client = ctx.platformApi;
|
|
28
28
|
ctx.cronRegistry.set(trigger.id, trigger.schedule);
|
|
29
|
-
async function handleSchedule(
|
|
29
|
+
async function handleSchedule(req, res, span) {
|
|
30
30
|
try {
|
|
31
|
+
// run for a single activation
|
|
32
|
+
const activationId = req.params.activationId;
|
|
33
|
+
if (activationId) {
|
|
34
|
+
const { data: activation } = await client.getActivation({
|
|
35
|
+
path: {
|
|
36
|
+
organisation_id: ctx.organisationId,
|
|
37
|
+
environment_id: environmentId,
|
|
38
|
+
activation_id: activationId,
|
|
39
|
+
},
|
|
40
|
+
throwOnError: false,
|
|
41
|
+
});
|
|
42
|
+
if (!activation) {
|
|
43
|
+
res.status(412).json({
|
|
44
|
+
status: 'error',
|
|
45
|
+
message: `No activation found for ID: ${activationId}`,
|
|
46
|
+
});
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const executionCtx = ctx.contextProvider.create(activation, {}, { workflowId: trigger.id });
|
|
50
|
+
span.setAttribute('execution.id', executionCtx.executionId);
|
|
51
|
+
await sendTaskStartEvent(trigger.id, executionCtx, span);
|
|
52
|
+
try {
|
|
53
|
+
ctx.log.info(`Running schedule ${trigger.id} for activation ${activationId}`);
|
|
54
|
+
subscriber.next(executionCtx);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
executionCtx.log.error('execution error inside schedule', { error });
|
|
58
|
+
}
|
|
59
|
+
res.status(200).json({
|
|
60
|
+
status: 'triggered',
|
|
61
|
+
executionId: executionCtx.executionId,
|
|
62
|
+
});
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
// run for static activation only
|
|
31
66
|
if (trigger.activationPredicate === undefined) {
|
|
32
67
|
const { data: activation } = await client.listActivations({
|
|
33
68
|
path: {
|
|
@@ -61,6 +96,7 @@ function compileSchedule(ctx, trigger, signal) {
|
|
|
61
96
|
});
|
|
62
97
|
return;
|
|
63
98
|
}
|
|
99
|
+
// run for all activations
|
|
64
100
|
const { data: activations } = await client.listActivations({
|
|
65
101
|
path: {
|
|
66
102
|
organisation_id: ctx.organisationId,
|
|
@@ -81,6 +117,7 @@ function compileSchedule(ctx, trigger, signal) {
|
|
|
81
117
|
activations.forEach((activation) => {
|
|
82
118
|
const executionCtx = ctx.contextProvider.create(activation, {}, { workflowId: trigger.id });
|
|
83
119
|
try {
|
|
120
|
+
ctx.log.info(`Running schedule ${trigger.id} for activation ${activation.id}`);
|
|
84
121
|
subscriber.next(executionCtx);
|
|
85
122
|
}
|
|
86
123
|
catch (error) {
|
|
@@ -109,6 +146,22 @@ function compileSchedule(ctx, trigger, signal) {
|
|
|
109
146
|
span.end();
|
|
110
147
|
});
|
|
111
148
|
});
|
|
149
|
+
ctx.cronRouter.post(`/cron/${trigger.id}/activations/:activationId`, async (req, res) => {
|
|
150
|
+
await ctx.tracer.startActiveSpan(`schedule-${trigger.id}`, async (span) => {
|
|
151
|
+
span.setAttribute('task.id', trigger.id);
|
|
152
|
+
span.setAttribute('activation.id', req.params.activationId);
|
|
153
|
+
span.setAttribute('task.type', 'schedule');
|
|
154
|
+
span.setAttribute('type', 'task');
|
|
155
|
+
span.setAttribute('schedule', trigger.schedule);
|
|
156
|
+
span.setAttribute('project.id', projectId);
|
|
157
|
+
span.setAttribute('environment.id', environmentId);
|
|
158
|
+
span.setAttribute('environment.name', environmentName);
|
|
159
|
+
span.setAttribute('org.id', orgId);
|
|
160
|
+
span.setAttribute('workflow.id', trigger.id);
|
|
161
|
+
await handleSchedule(req, res, span);
|
|
162
|
+
span.end();
|
|
163
|
+
});
|
|
164
|
+
});
|
|
112
165
|
function cleanup() {
|
|
113
166
|
ctx.log.debug('scheduler trigger stopped');
|
|
114
167
|
subscriber.complete();
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FetchBuilder.d.ts","sourceRoot":"","sources":["../../../../src/src/connection/internal/FetchBuilder.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE5D,MAAM,MAAM,eAAe,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB,
|
|
1
|
+
{"version":3,"file":"FetchBuilder.d.ts","sourceRoot":"","sources":["../../../../src/src/connection/internal/FetchBuilder.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE5D,MAAM,MAAM,eAAe,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;GAIG;AACH,qBAAa,YAAY;;IACrB,WAAW,EAAE,kBAAkB,EAAE,CAAC;gBAMtB,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,eAAe;IAelD,GAAG,CAAC,EAAE,EAAE,kBAAkB;IAI1B,KAAK,IAAI,SAAS;IAYlB,oBAAoB,IAAI,SAAS;IAOjC,OAAO,CAAC,eAAe;IAevB,OAAO,CAAC,eAAe;CAyF1B"}
|
|
@@ -96,7 +96,7 @@ class FetchBuilder {
|
|
|
96
96
|
}
|
|
97
97
|
// during testing the user can choose to use a real connection or AI mock.
|
|
98
98
|
// so in supervised mode this function is used instead of the normal build() function.
|
|
99
|
-
// and it will make the
|
|
99
|
+
// and it will make the decision on using mock or real at runtime at the cost of performance
|
|
100
100
|
supervisedFetch() {
|
|
101
101
|
return (input, init) => {
|
|
102
102
|
let fetch = (input, init) => {
|
|
@@ -122,19 +122,25 @@ class FetchBuilder {
|
|
|
122
122
|
span.setAttribute('connection.id', connectionId);
|
|
123
123
|
span.setAttribute('connection.name', connectionName);
|
|
124
124
|
span.setAttribute('isConnected', connectionId !== '');
|
|
125
|
-
if (init?.method) {
|
|
126
|
-
span.setAttribute('http.method', init.method);
|
|
127
|
-
}
|
|
128
125
|
try {
|
|
129
126
|
const response = await fetch(input, init);
|
|
130
127
|
if (supervisor_js_1.enabled) {
|
|
128
|
+
if (init?.method) {
|
|
129
|
+
span.setAttribute('http.method', init.method);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
span.setAttribute('http.method', 'GET');
|
|
133
|
+
}
|
|
131
134
|
// when we are in supervisor mode, we need to store the response body in the span attribute
|
|
132
135
|
// this will be shown the end-user in some UI in the future(the future is now)
|
|
133
136
|
const body = await response.clone().arrayBuffer();
|
|
134
137
|
// if response is text/* or json we store the body as a string, otherwise we store it as a base64 string
|
|
135
138
|
const contentType = response.headers.get('Content-Type');
|
|
136
139
|
span.setAttribute('response.content_type', contentType || '');
|
|
137
|
-
|
|
140
|
+
span.setAttribute('request.headers', JSON.stringify(init?.headers || {}));
|
|
141
|
+
if (contentType &&
|
|
142
|
+
(contentType.startsWith('text/') ||
|
|
143
|
+
contentType.startsWith('application/json'))) {
|
|
138
144
|
span.setAttribute('response.body', new TextDecoder().decode(body));
|
|
139
145
|
}
|
|
140
146
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InternalAuth.d.ts","sourceRoot":"","sources":["../../../src/src/internal/InternalAuth.ts"],"names":[],"mappings":"AAoBA,KAAK,kBAAkB,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAEpD,qBAAa,YAAY;IACrB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,aAAa,CAAS;IAE9B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,SAAS,CAAS;;
|
|
1
|
+
{"version":3,"file":"InternalAuth.d.ts","sourceRoot":"","sources":["../../../src/src/internal/InternalAuth.ts"],"names":[],"mappings":"AAoBA,KAAK,kBAAkB,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAEpD,qBAAa,YAAY;IACrB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,aAAa,CAAS;IAE9B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,SAAS,CAAS;;IAyBpB,aAAa,IAAI,OAAO,CAAC,kBAAkB,CAAC;CAsBrD"}
|
|
@@ -54,7 +54,6 @@ class InternalAuth {
|
|
|
54
54
|
if (Deno.env.get(constants_js_1.envVarInternalToken)) {
|
|
55
55
|
this.accessToken = Deno.env.get(constants_js_1.envVarInternalToken) || '';
|
|
56
56
|
this.expiresAt = Date.now() + 365 * 24 * 60 * 60 * 1000; // expires in 1 year
|
|
57
|
-
console.log(`Using static token provided by ${constants_js_1.envVarInternalToken}`);
|
|
58
57
|
return;
|
|
59
58
|
}
|
|
60
59
|
if (!this.clientId || !this.clientSecret || !this.tokenEndpoint) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supervisor.d.ts","sourceRoot":"","sources":["../../../src/src/internal/supervisor.ts"],"names":[],"mappings":"AAaA,OAAO,EACH,YAAY,EAIf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE3E,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"supervisor.d.ts","sourceRoot":"","sources":["../../../src/src/internal/supervisor.ts"],"names":[],"mappings":"AAaA,OAAO,EACH,YAAY,EAIf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE3E,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AA2ClD,eAAO,MAAM,OAAO,SAEhB,CAAC;AA2BL,KAAK,cAAc,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AA0DF,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAYjD;AAED,wBAAsB,gBAAgB,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CA0BxF;AAED,wBAAsB,kBAAkB,CAAC,CAAC,EAAE,CAAC,EACzC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EACtB,IAAI,EAAE,IAAI,GACX,OAAO,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAwC5B;AAED,wBAAsB,cAAc,CAChC,IAAI,EAAE,WAAW,GAAG,GAAG,EACvB,GAAG,CAAC,EAAE,cAAc,EACpB,OAAO,CAAC,EAAE,WAAW,GACtB,OAAO,CAAC,QAAQ,CAAC,CAoCnB;AA0BD,qBAAa,IAAK,YAAW,YAAY;;IAOrC,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE,cAAc,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,GAAG,IAAI;IAmBnF,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAIzB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAG9B"}
|
|
@@ -24,6 +24,11 @@ const ScheduleTrigger_js_1 = require("../dsl/triggers/ScheduleTrigger.js");
|
|
|
24
24
|
const WebhookTrigger_js_1 = require("../dsl/triggers/WebhookTrigger.js");
|
|
25
25
|
const DurableTrigger_js_1 = require("../dsl/triggers/DurableTrigger.js");
|
|
26
26
|
const Task_js_1 = require("../dsl/Task.js");
|
|
27
|
+
const CatchTask_js_1 = require("../dsl/tasks/CatchTask.js");
|
|
28
|
+
const FnTask_js_1 = require("../dsl/tasks/FnTask.js");
|
|
29
|
+
const HttpTask_js_1 = require("../dsl/tasks/HttpTask.js");
|
|
30
|
+
const BackgroundTask_js_1 = require("../dsl/tasks/BackgroundTask.js");
|
|
31
|
+
const ParallelTask_js_1 = require("../dsl/tasks/ParallelTask.js");
|
|
27
32
|
const supervisorURL = (function () {
|
|
28
33
|
return Deno.env.get('RUN_SUPERVISOR_URL') || '';
|
|
29
34
|
})();
|
|
@@ -40,7 +45,7 @@ const flows = (function () {
|
|
|
40
45
|
nodes[node.id] = {
|
|
41
46
|
description: node?.data?.description,
|
|
42
47
|
steps: node?.data?.steps,
|
|
43
|
-
files: node?.data?.files[0]
|
|
48
|
+
files: node?.data?.files[0],
|
|
44
49
|
};
|
|
45
50
|
}
|
|
46
51
|
return nodes;
|
|
@@ -74,13 +79,40 @@ function getTriggerData(workflow) {
|
|
|
74
79
|
return null;
|
|
75
80
|
}
|
|
76
81
|
function getTaskData(task) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
82
|
+
let taskData = [];
|
|
83
|
+
if (task instanceof ChainTask_js_1.ChainTask) {
|
|
84
|
+
taskData = task.tasks.map((t) => getTaskData(t)).flat();
|
|
85
|
+
}
|
|
86
|
+
else if (task instanceof CatchTask_js_1.CatchTask) {
|
|
87
|
+
taskData = [...getTaskData(task._base), ...getTaskData(task._errorHandler)];
|
|
88
|
+
}
|
|
89
|
+
else if (task instanceof BackgroundTask_js_1.BackgroundTask) {
|
|
90
|
+
taskData = getTaskData(task._base);
|
|
91
|
+
}
|
|
92
|
+
else if (task instanceof ParallelTask_js_1.ParallelTask) {
|
|
93
|
+
// I'm not sure if this is correct, but I don't think there are any ParallelTasks out in the wild yet
|
|
94
|
+
taskData = [...getTaskData(task._base), ...getTaskData(task._each)];
|
|
95
|
+
}
|
|
96
|
+
else if (task instanceof FnTask_js_1.FnTask) {
|
|
97
|
+
taskData.push({
|
|
98
|
+
taskId: task.id,
|
|
99
|
+
type: task[Task_js_1.TaskType].toLowerCase(),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
else if (task instanceof HttpTask_js_1.HttpTaskImpl) {
|
|
103
|
+
taskData.push({
|
|
104
|
+
taskId: task.id,
|
|
105
|
+
type: task[Task_js_1.TaskType].toLowerCase(),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
// yolo
|
|
110
|
+
taskData.push({
|
|
111
|
+
taskId: String(task.id || 'unknown'),
|
|
112
|
+
type: task[Task_js_1.TaskType].toLowerCase(),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return taskData;
|
|
84
116
|
}
|
|
85
117
|
async function signalReady() {
|
|
86
118
|
if (!exports.enabled) {
|
|
@@ -99,19 +131,15 @@ async function registerWorkflow(workflow) {
|
|
|
99
131
|
if (!exports.enabled) {
|
|
100
132
|
return;
|
|
101
133
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
trigger: triggerData,
|
|
112
|
-
tasks,
|
|
113
|
-
};
|
|
114
|
-
try {
|
|
134
|
+
const triggerData = getTriggerData(workflow);
|
|
135
|
+
const tasks = getTaskData(workflow.task);
|
|
136
|
+
try {
|
|
137
|
+
if (triggerData) {
|
|
138
|
+
const data = {
|
|
139
|
+
workflowId: triggerData.id,
|
|
140
|
+
trigger: triggerData,
|
|
141
|
+
tasks,
|
|
142
|
+
};
|
|
115
143
|
await fetch(`${supervisorURL}/register-workflow`, {
|
|
116
144
|
method: 'POST',
|
|
117
145
|
body: JSON.stringify(data),
|
|
@@ -120,9 +148,9 @@ async function registerWorkflow(workflow) {
|
|
|
120
148
|
},
|
|
121
149
|
});
|
|
122
150
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
151
|
+
}
|
|
152
|
+
catch (err) {
|
|
153
|
+
logger.error('Failed to register workflow with supervisor', { error: err });
|
|
126
154
|
}
|
|
127
155
|
}
|
|
128
156
|
async function sendTaskStartEvent(taskId, ctx, span) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fn.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/fn.ts"],"names":[],"mappings":"AA+BA,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAGtD,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"fn.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/fn.ts"],"names":[],"mappings":"AA+BA,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"}
|
|
@@ -17,11 +17,9 @@ const rxjs_1 = require("rxjs");
|
|
|
17
17
|
const FnTask_js_1 = require("../../../dsl/tasks/FnTask.js");
|
|
18
18
|
const supervisor_js_1 = require("../../../internal/supervisor.js");
|
|
19
19
|
function compileFn(compilerCtx, task) {
|
|
20
|
-
return (src) => src.pipe((0, rxjs_1.
|
|
21
|
-
complete: () => compilerCtx.log.debug('fn.complete'),
|
|
22
|
-
}), (0, rxjs_1.mergeMap)(async (ctx) => {
|
|
20
|
+
return (src) => src.pipe((0, rxjs_1.mergeMap)(async (ctx) => {
|
|
23
21
|
return await compilerCtx.tracer.startActiveSpan(`fn-${task.id}`, async (span) => {
|
|
24
|
-
await (0, supervisor_js_1.sendTaskStartEvent)(task.id, span);
|
|
22
|
+
await (0, supervisor_js_1.sendTaskStartEvent)(task.id, ctx, span);
|
|
25
23
|
span.setAttribute('task.id', task.id);
|
|
26
24
|
span.setAttribute('type', 'task');
|
|
27
25
|
span.setAttribute('task.type', 'fn');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/http.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAmB,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAG/E,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/http.ts"],"names":[],"mappings":"AAqBA,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"}
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.httpCompiler = void 0;
|
|
16
16
|
const rxjs_1 = require("rxjs");
|
|
17
|
-
const operators_1 = require("rxjs/operators");
|
|
18
17
|
const DynamicFetchFactory_js_1 = require("../../../connection/DynamicFetchFactory.js");
|
|
19
18
|
const FetchBuilder_js_1 = require("../../../connection/internal/FetchBuilder.js");
|
|
20
19
|
const StaticFetchFactory_js_1 = require("../../../connection/StaticFetchFactory.js");
|
|
@@ -72,11 +71,9 @@ function compileHttp(compilerCtx, task) {
|
|
|
72
71
|
const result = await task.fn(httpContext);
|
|
73
72
|
return ctx.withData(result);
|
|
74
73
|
}
|
|
75
|
-
return (src) => src.pipe((0,
|
|
76
|
-
complete: () => compilerCtx.log.debug('http.complete'),
|
|
77
|
-
}), (0, rxjs_1.mergeMap)((ctx) => {
|
|
74
|
+
return (src) => src.pipe((0, rxjs_1.mergeMap)((ctx) => {
|
|
78
75
|
return compilerCtx.tracer.startActiveSpan(`http-${task.id}`, async (span) => {
|
|
79
|
-
await (0, supervisor_js_1.sendTaskStartEvent)(task.id, span);
|
|
76
|
+
await (0, supervisor_js_1.sendTaskStartEvent)(task.id, ctx, span);
|
|
80
77
|
span.setAttribute('task.id', task.id);
|
|
81
78
|
span.setAttribute('task.type', 'http');
|
|
82
79
|
span.setAttribute('type', 'task');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fn.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/fn.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAGtD,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":"AAgBA,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"}
|
|
@@ -5,9 +5,7 @@ const rxjs_1 = require("rxjs");
|
|
|
5
5
|
const FnTask_js_1 = require("../../../dsl/tasks/FnTask.js");
|
|
6
6
|
const supervisor_js_1 = require("../../../internal/supervisor.js");
|
|
7
7
|
function compileFn(compilerCtx, task) {
|
|
8
|
-
return (src) => src.pipe((0, rxjs_1.
|
|
9
|
-
complete: () => compilerCtx.log.debug('fn.complete'),
|
|
10
|
-
}), (0, rxjs_1.mergeMap)(async (ctx) => {
|
|
8
|
+
return (src) => src.pipe((0, rxjs_1.mergeMap)(async (ctx) => {
|
|
11
9
|
return await compilerCtx.tracer.startActiveSpan(`fn-${task.id}`, async (span) => {
|
|
12
10
|
ctx = await (0, supervisor_js_1.sendTaskStartEvent)(task.id, ctx, span);
|
|
13
11
|
span.setAttribute('task.id', task.id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/http.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAmB,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAG/E,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/http.ts"],"names":[],"mappings":"AAqBA,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"}
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.httpCompiler = void 0;
|
|
16
16
|
const rxjs_1 = require("rxjs");
|
|
17
|
-
const operators_1 = require("rxjs/operators");
|
|
18
17
|
const DynamicFetchFactory_js_1 = require("../../../connection/DynamicFetchFactory.js");
|
|
19
18
|
const FetchBuilder_js_1 = require("../../../connection/internal/FetchBuilder.js");
|
|
20
19
|
const StaticFetchFactory_js_1 = require("../../../connection/StaticFetchFactory.js");
|
|
@@ -72,9 +71,7 @@ function compileHttp(compilerCtx, task) {
|
|
|
72
71
|
const result = await task.fn(httpContext);
|
|
73
72
|
return ctx.withData(result);
|
|
74
73
|
}
|
|
75
|
-
return (src) => src.pipe((0,
|
|
76
|
-
complete: () => compilerCtx.log.debug('http.complete'),
|
|
77
|
-
}), (0, rxjs_1.mergeMap)((ctx) => {
|
|
74
|
+
return (src) => src.pipe((0, rxjs_1.mergeMap)((ctx) => {
|
|
78
75
|
return compilerCtx.tracer.startActiveSpan(`http-${task.id}`, async (span) => {
|
|
79
76
|
ctx = await (0, supervisor_js_1.sendTaskStartEvent)(task.id, ctx, span);
|
|
80
77
|
span.setAttribute('task.id', task.id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/schedule.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;
|
|
1
|
+
{"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/schedule.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AASzF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA8M7C,eAAO,MAAM,gBAAgB,EAAE,eAAe,CAAC,YAAY,EAAE,eAAe,CAG3E,CAAC"}
|
|
@@ -29,8 +29,43 @@ function compileSchedule(ctx, trigger, signal) {
|
|
|
29
29
|
const orgId = Deno.env.get(constants_js_1.envVarOrgId) || 'example-org';
|
|
30
30
|
const client = ctx.platformApi;
|
|
31
31
|
ctx.cronRegistry.set(trigger.id, trigger.schedule);
|
|
32
|
-
async function handleSchedule(
|
|
32
|
+
async function handleSchedule(req, res, span) {
|
|
33
33
|
try {
|
|
34
|
+
// run for a single activation
|
|
35
|
+
const activationId = req.params.activationId;
|
|
36
|
+
if (activationId) {
|
|
37
|
+
const { data: activation } = await client.getActivation({
|
|
38
|
+
path: {
|
|
39
|
+
organisation_id: ctx.organisationId,
|
|
40
|
+
environment_id: environmentId,
|
|
41
|
+
activation_id: activationId,
|
|
42
|
+
},
|
|
43
|
+
throwOnError: false,
|
|
44
|
+
});
|
|
45
|
+
if (!activation) {
|
|
46
|
+
res.status(412).json({
|
|
47
|
+
status: 'error',
|
|
48
|
+
message: `No activation found for ID: ${activationId}`,
|
|
49
|
+
});
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const executionCtx = ctx.contextProvider.create(activation, {}, { workflowId: trigger.id });
|
|
53
|
+
span.setAttribute('execution.id', executionCtx.executionId);
|
|
54
|
+
await (0, supervisor_js_1.sendTaskStartEvent)(trigger.id, executionCtx, span);
|
|
55
|
+
try {
|
|
56
|
+
ctx.log.info(`Running schedule ${trigger.id} for activation ${activationId}`);
|
|
57
|
+
subscriber.next(executionCtx);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
executionCtx.log.error('execution error inside schedule', { error });
|
|
61
|
+
}
|
|
62
|
+
res.status(200).json({
|
|
63
|
+
status: 'triggered',
|
|
64
|
+
executionId: executionCtx.executionId,
|
|
65
|
+
});
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
// run for static activation only
|
|
34
69
|
if (trigger.activationPredicate === undefined) {
|
|
35
70
|
const { data: activation } = await client.listActivations({
|
|
36
71
|
path: {
|
|
@@ -64,6 +99,7 @@ function compileSchedule(ctx, trigger, signal) {
|
|
|
64
99
|
});
|
|
65
100
|
return;
|
|
66
101
|
}
|
|
102
|
+
// run for all activations
|
|
67
103
|
const { data: activations } = await client.listActivations({
|
|
68
104
|
path: {
|
|
69
105
|
organisation_id: ctx.organisationId,
|
|
@@ -84,6 +120,7 @@ function compileSchedule(ctx, trigger, signal) {
|
|
|
84
120
|
activations.forEach((activation) => {
|
|
85
121
|
const executionCtx = ctx.contextProvider.create(activation, {}, { workflowId: trigger.id });
|
|
86
122
|
try {
|
|
123
|
+
ctx.log.info(`Running schedule ${trigger.id} for activation ${activation.id}`);
|
|
87
124
|
subscriber.next(executionCtx);
|
|
88
125
|
}
|
|
89
126
|
catch (error) {
|
|
@@ -112,6 +149,22 @@ function compileSchedule(ctx, trigger, signal) {
|
|
|
112
149
|
span.end();
|
|
113
150
|
});
|
|
114
151
|
});
|
|
152
|
+
ctx.cronRouter.post(`/cron/${trigger.id}/activations/:activationId`, async (req, res) => {
|
|
153
|
+
await ctx.tracer.startActiveSpan(`schedule-${trigger.id}`, async (span) => {
|
|
154
|
+
span.setAttribute('task.id', trigger.id);
|
|
155
|
+
span.setAttribute('activation.id', req.params.activationId);
|
|
156
|
+
span.setAttribute('task.type', 'schedule');
|
|
157
|
+
span.setAttribute('type', 'task');
|
|
158
|
+
span.setAttribute('schedule', trigger.schedule);
|
|
159
|
+
span.setAttribute('project.id', projectId);
|
|
160
|
+
span.setAttribute('environment.id', environmentId);
|
|
161
|
+
span.setAttribute('environment.name', environmentName);
|
|
162
|
+
span.setAttribute('org.id', orgId);
|
|
163
|
+
span.setAttribute('workflow.id', trigger.id);
|
|
164
|
+
await handleSchedule(req, res, span);
|
|
165
|
+
span.end();
|
|
166
|
+
});
|
|
167
|
+
});
|
|
115
168
|
function cleanup() {
|
|
116
169
|
ctx.log.debug('scheduler trigger stopped');
|
|
117
170
|
subscriber.complete();
|