@versori/run 0.2.13 → 0.2.15
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.d.ts +14 -0
- package/esm/src/context/AsyncWorkflow.d.ts.map +1 -0
- package/esm/src/context/AsyncWorkflow.js +89 -0
- package/esm/src/context/Context.d.ts +12 -1
- package/esm/src/context/Context.d.ts.map +1 -1
- package/esm/src/context/Context.js +43 -4
- package/esm/src/context/ContextProvider.d.ts +3 -1
- package/esm/src/context/ContextProvider.d.ts.map +1 -1
- package/esm/src/context/ContextProvider.js +9 -2
- package/esm/src/dsl/http/versori/constants.d.ts +1 -0
- package/esm/src/dsl/http/versori/constants.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/constants.js +1 -0
- package/esm/src/dsl/triggers/DurableTrigger.d.ts +17 -0
- package/esm/src/dsl/triggers/DurableTrigger.d.ts.map +1 -0
- package/esm/src/dsl/triggers/DurableTrigger.js +36 -0
- package/esm/src/dsl/triggers/mod.d.ts +1 -0
- package/esm/src/dsl/triggers/mod.d.ts.map +1 -1
- package/esm/src/dsl/triggers/mod.js +1 -0
- package/esm/src/interpreter/durable/DurableInterpreter.d.ts +52 -0
- package/esm/src/interpreter/durable/DurableInterpreter.d.ts.map +1 -0
- package/esm/src/interpreter/durable/DurableInterpreter.js +433 -0
- package/esm/src/interpreter/durable/ExecutionError.d.ts +6 -0
- package/esm/src/interpreter/durable/ExecutionError.d.ts.map +1 -0
- package/esm/src/interpreter/durable/ExecutionError.js +13 -0
- package/esm/src/interpreter/durable/ObservableCompiler.d.ts +35 -0
- package/esm/src/interpreter/durable/ObservableCompiler.d.ts.map +1 -0
- package/esm/src/interpreter/durable/ObservableCompiler.js +69 -0
- package/esm/src/interpreter/durable/Queue.d.ts +60 -0
- package/esm/src/interpreter/durable/Queue.d.ts.map +1 -0
- package/esm/src/interpreter/durable/Queue.js +131 -0
- package/esm/src/interpreter/durable/compilers/background.d.ts +4 -0
- package/esm/src/interpreter/durable/compilers/background.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/background.js +22 -0
- package/esm/src/interpreter/durable/compilers/catch.d.ts +4 -0
- package/esm/src/interpreter/durable/compilers/catch.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/catch.js +36 -0
- package/esm/src/interpreter/durable/compilers/chain.d.ts +3 -0
- package/esm/src/interpreter/durable/compilers/chain.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/chain.js +9 -0
- package/esm/src/interpreter/durable/compilers/durableworkflow.d.ts +8 -0
- package/esm/src/interpreter/durable/compilers/durableworkflow.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/durableworkflow.js +54 -0
- package/esm/src/interpreter/durable/compilers/fn.d.ts +4 -0
- package/esm/src/interpreter/durable/compilers/fn.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/fn.js +22 -0
- package/esm/src/interpreter/durable/compilers/http.d.ts +4 -0
- package/esm/src/interpreter/durable/compilers/http.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/http.js +44 -0
- package/esm/src/interpreter/durable/compilers/mod.d.ts +2 -0
- package/esm/src/interpreter/durable/compilers/mod.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/mod.js +1 -0
- package/esm/src/interpreter/durable/compilers/parallel.d.ts +4 -0
- package/esm/src/interpreter/durable/compilers/parallel.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/parallel.js +19 -0
- package/esm/src/interpreter/durable/compilers/schedule.d.ts +4 -0
- package/esm/src/interpreter/durable/compilers/schedule.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/schedule.js +94 -0
- package/esm/src/interpreter/durable/compilers/serial.d.ts +4 -0
- package/esm/src/interpreter/durable/compilers/serial.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/serial.js +16 -0
- package/esm/src/interpreter/durable/compilers/types.d.ts +15 -0
- package/esm/src/interpreter/durable/compilers/types.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/types.js +1 -0
- package/esm/src/interpreter/durable/compilers/unpack.d.ts +4 -0
- package/esm/src/interpreter/durable/compilers/unpack.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/unpack.js +22 -0
- package/esm/src/interpreter/durable/compilers/webhook.d.ts +4 -0
- package/esm/src/interpreter/durable/compilers/webhook.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/webhook.js +248 -0
- package/esm/src/interpreter/durable/mod.d.ts +5 -0
- package/esm/src/interpreter/durable/mod.d.ts.map +1 -0
- package/esm/src/interpreter/durable/mod.js +4 -0
- package/esm/src/interpreter/memory/MemoryInterpreter.js +1 -1
- package/esm/src/interpreter/mod.d.ts +1 -0
- package/esm/src/interpreter/mod.d.ts.map +1 -1
- package/esm/src/interpreter/mod.js +1 -0
- package/package.json +1 -1
- package/script/src/context/AsyncWorkflow.d.ts +14 -0
- package/script/src/context/AsyncWorkflow.d.ts.map +1 -0
- package/script/src/context/AsyncWorkflow.js +93 -0
- package/script/src/context/Context.d.ts +12 -1
- package/script/src/context/Context.d.ts.map +1 -1
- package/script/src/context/Context.js +43 -4
- package/script/src/context/ContextProvider.d.ts +3 -1
- package/script/src/context/ContextProvider.d.ts.map +1 -1
- package/script/src/context/ContextProvider.js +9 -2
- package/script/src/dsl/http/versori/constants.d.ts +1 -0
- package/script/src/dsl/http/versori/constants.d.ts.map +1 -1
- package/script/src/dsl/http/versori/constants.js +2 -1
- package/script/src/dsl/triggers/DurableTrigger.d.ts +17 -0
- package/script/src/dsl/triggers/DurableTrigger.d.ts.map +1 -0
- package/script/src/dsl/triggers/DurableTrigger.js +41 -0
- package/script/src/dsl/triggers/mod.d.ts +1 -0
- package/script/src/dsl/triggers/mod.d.ts.map +1 -1
- package/script/src/dsl/triggers/mod.js +3 -1
- package/script/src/interpreter/durable/DurableInterpreter.d.ts +52 -0
- package/script/src/interpreter/durable/DurableInterpreter.d.ts.map +1 -0
- package/script/src/interpreter/durable/DurableInterpreter.js +440 -0
- package/script/src/interpreter/durable/ExecutionError.d.ts +6 -0
- package/script/src/interpreter/durable/ExecutionError.d.ts.map +1 -0
- package/script/src/interpreter/durable/ExecutionError.js +17 -0
- package/script/src/interpreter/durable/ObservableCompiler.d.ts +35 -0
- package/script/src/interpreter/durable/ObservableCompiler.d.ts.map +1 -0
- package/script/src/interpreter/durable/ObservableCompiler.js +73 -0
- package/script/src/interpreter/durable/Queue.d.ts +60 -0
- package/script/src/interpreter/durable/Queue.d.ts.map +1 -0
- package/script/src/interpreter/durable/Queue.js +135 -0
- package/script/src/interpreter/durable/compilers/background.d.ts +4 -0
- package/script/src/interpreter/durable/compilers/background.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/background.js +25 -0
- package/script/src/interpreter/durable/compilers/catch.d.ts +4 -0
- package/script/src/interpreter/durable/compilers/catch.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/catch.js +39 -0
- package/script/src/interpreter/durable/compilers/chain.d.ts +3 -0
- package/script/src/interpreter/durable/compilers/chain.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/chain.js +12 -0
- package/script/src/interpreter/durable/compilers/durableworkflow.d.ts +8 -0
- package/script/src/interpreter/durable/compilers/durableworkflow.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/durableworkflow.js +58 -0
- package/script/src/interpreter/durable/compilers/fn.d.ts +4 -0
- package/script/src/interpreter/durable/compilers/fn.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/fn.js +25 -0
- package/script/src/interpreter/durable/compilers/http.d.ts +4 -0
- package/script/src/interpreter/durable/compilers/http.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/http.js +47 -0
- package/script/src/interpreter/durable/compilers/mod.d.ts +2 -0
- package/script/src/interpreter/durable/compilers/mod.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/mod.js +2 -0
- package/script/src/interpreter/durable/compilers/parallel.d.ts +4 -0
- package/script/src/interpreter/durable/compilers/parallel.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/parallel.js +22 -0
- package/script/src/interpreter/durable/compilers/schedule.d.ts +4 -0
- package/script/src/interpreter/durable/compilers/schedule.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/schedule.js +97 -0
- package/script/src/interpreter/durable/compilers/serial.d.ts +4 -0
- package/script/src/interpreter/durable/compilers/serial.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/serial.js +19 -0
- package/script/src/interpreter/durable/compilers/types.d.ts +15 -0
- package/script/src/interpreter/durable/compilers/types.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/types.js +2 -0
- package/script/src/interpreter/durable/compilers/unpack.d.ts +4 -0
- package/script/src/interpreter/durable/compilers/unpack.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/unpack.js +25 -0
- package/script/src/interpreter/durable/compilers/webhook.d.ts +4 -0
- package/script/src/interpreter/durable/compilers/webhook.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/webhook.js +254 -0
- package/script/src/interpreter/durable/mod.d.ts +5 -0
- package/script/src/interpreter/durable/mod.d.ts.map +1 -0
- package/script/src/interpreter/durable/mod.js +20 -0
- package/script/src/interpreter/memory/MemoryInterpreter.js +1 -1
- package/script/src/interpreter/mod.d.ts +1 -0
- package/script/src/interpreter/mod.d.ts.map +1 -1
- package/script/src/interpreter/mod.js +14 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cronPort = exports.envVarLocalRun = exports.envVarInternalToken = exports.envVarTokenEndpoint = exports.envVarClientSecret = exports.envVarClientId = exports.envVarConfigFile = exports.envVarVersion = exports.envVarOtelTracesURL = exports.envVarCredsBaseURL = exports.envVarSelfRefURL = exports.envVarCronApiBaseURL = exports.envVarPlatformApiBaseURL = exports.envVarOrgSlug = exports.envVarProjectId = exports.envVarEnvironmentName = exports.envVarEnvId = exports.envVarOrgId = void 0;
|
|
3
|
+
exports.cronPort = exports.envVarLocalRun = exports.envVarInternalToken = exports.envVarTokenEndpoint = exports.envVarClientSecret = exports.envVarClientId = exports.envVarConfigFile = exports.envVarVersion = exports.envVarOtelTracesURL = exports.envVarCredsBaseURL = exports.envVarSelfRefURL = exports.envVarWorkflowApiBaseURL = exports.envVarCronApiBaseURL = exports.envVarPlatformApiBaseURL = exports.envVarOrgSlug = exports.envVarProjectId = exports.envVarEnvironmentName = exports.envVarEnvId = exports.envVarOrgId = void 0;
|
|
4
4
|
// This file contains constants used in the Versori DSL HTTP client.
|
|
5
5
|
exports.envVarOrgId = 'RUN_ORGANISATION_ID';
|
|
6
6
|
exports.envVarEnvId = 'RUN_ENVIRONMENT_ID';
|
|
@@ -9,6 +9,7 @@ exports.envVarProjectId = 'RUN_SERVICE_ID';
|
|
|
9
9
|
exports.envVarOrgSlug = 'RUN_ORGANISATION_SLUG';
|
|
10
10
|
exports.envVarPlatformApiBaseURL = 'RUN_PLATFORM_API_INTERNAL_URL';
|
|
11
11
|
exports.envVarCronApiBaseURL = 'RUN_CRON_API_INTERNAL_URL';
|
|
12
|
+
exports.envVarWorkflowApiBaseURL = 'RUN_SDK_API_URL';
|
|
12
13
|
exports.envVarSelfRefURL = 'RUN_SELF_REF_URL';
|
|
13
14
|
exports.envVarCredsBaseURL = 'RUN_CREDENTIALS_SERVICE_INTERNAL_URL';
|
|
14
15
|
exports.envVarOtelTracesURL = 'RUN_OTEL_TRACES_URL';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Taskable } from '../mod.js';
|
|
2
|
+
import { Trigger, TriggerType } from '../Trigger.js';
|
|
3
|
+
import { Workflow } from '../Workflow.js';
|
|
4
|
+
export type DurableWorkflowOptions = {
|
|
5
|
+
ttl?: number;
|
|
6
|
+
limit?: number;
|
|
7
|
+
};
|
|
8
|
+
export type DurableWorkflowData = Record<string, unknown>;
|
|
9
|
+
export declare class DurableWorkflowTrigger implements Trigger<DurableWorkflowData> {
|
|
10
|
+
id: string;
|
|
11
|
+
options: DurableWorkflowOptions;
|
|
12
|
+
[TriggerType]: string;
|
|
13
|
+
constructor(id: string, options?: DurableWorkflowOptions);
|
|
14
|
+
then<OO>(task: Taskable<DurableWorkflowData, OO>): Workflow<OO>;
|
|
15
|
+
}
|
|
16
|
+
export declare function workflow(id: string, options?: DurableWorkflowOptions): Trigger<DurableWorkflowData>;
|
|
17
|
+
//# sourceMappingURL=DurableTrigger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DurableTrigger.d.ts","sourceRoot":"","sources":["../../../../src/src/dsl/triggers/DurableTrigger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAgB,MAAM,gBAAgB,CAAC;AAExD,MAAM,MAAM,sBAAsB,GAAG;IACjC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE1D,qBAAa,sBAAuB,YAAW,OAAO,CAAC,mBAAmB,CAAC;IACvE,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,sBAAsB,CAAC;IAEhC,CAAC,WAAW,CAAC,EAAE,MAAM,CAAqB;gBAE9B,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,sBAA2B;IAK5D,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,mBAAmB,EAAE,EAAE,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC;CAIlE;AAED,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAEnG"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.DurableWorkflowTrigger = void 0;
|
|
5
|
+
exports.workflow = workflow;
|
|
6
|
+
const ensureTask_js_1 = require("../ensureTask.js");
|
|
7
|
+
const Trigger_js_1 = require("../Trigger.js");
|
|
8
|
+
const Workflow_js_1 = require("../Workflow.js");
|
|
9
|
+
class DurableWorkflowTrigger {
|
|
10
|
+
constructor(id, options = {}) {
|
|
11
|
+
Object.defineProperty(this, "id", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: void 0
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(this, "options", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: void 0
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(this, _a, {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: 'durableWorkflow'
|
|
28
|
+
});
|
|
29
|
+
this.id = id;
|
|
30
|
+
this.options = options;
|
|
31
|
+
}
|
|
32
|
+
then(task) {
|
|
33
|
+
return new Workflow_js_1.WorkflowImpl(this, (0, ensureTask_js_1.ensureTask)(task));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.DurableWorkflowTrigger = DurableWorkflowTrigger;
|
|
37
|
+
_a = Trigger_js_1.TriggerType;
|
|
38
|
+
;
|
|
39
|
+
function workflow(id, options) {
|
|
40
|
+
return new DurableWorkflowTrigger(id, options);
|
|
41
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../src/src/dsl/triggers/mod.ts"],"names":[],"mappings":"AAAA,mBAAmB,sBAAsB,CAAC;AAC1C,mBAAmB,qBAAqB,CAAC;AAEzC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../src/src/dsl/triggers/mod.ts"],"names":[],"mappings":"AAAA,mBAAmB,sBAAsB,CAAC;AAC1C,mBAAmB,qBAAqB,CAAC;AAEzC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.webhook = exports.schedule = void 0;
|
|
3
|
+
exports.workflow = exports.webhook = exports.schedule = void 0;
|
|
4
4
|
var ScheduleTrigger_js_1 = require("./ScheduleTrigger.js");
|
|
5
5
|
Object.defineProperty(exports, "schedule", { enumerable: true, get: function () { return ScheduleTrigger_js_1.schedule; } });
|
|
6
6
|
var WebhookTrigger_js_1 = require("./WebhookTrigger.js");
|
|
7
7
|
Object.defineProperty(exports, "webhook", { enumerable: true, get: function () { return WebhookTrigger_js_1.webhook; } });
|
|
8
|
+
var DurableTrigger_js_1 = require("./DurableTrigger.js");
|
|
9
|
+
Object.defineProperty(exports, "workflow", { enumerable: true, get: function () { return DurableTrigger_js_1.workflow; } });
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Tracer } from '@opentelemetry/api';
|
|
2
|
+
import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
3
|
+
import { Router } from 'express';
|
|
4
|
+
import { Observable, Subscription } from 'rxjs';
|
|
5
|
+
import { ContextProvider } from '../../context/ContextProvider.js';
|
|
6
|
+
import { ConfigReader, ConnectionProvider, CronProvider, RoundTripperFactory } from '../../dsl/http/types.js';
|
|
7
|
+
import { Workflow } from '../../dsl/Workflow.js';
|
|
8
|
+
import { ContextImpl, ContextOperatorFunction } from '../../mod.js';
|
|
9
|
+
import { Logger } from '../../observability/logging/Logger.js';
|
|
10
|
+
import { ObservableCompiler } from './ObservableCompiler.js';
|
|
11
|
+
import { QueueAPI } from './Queue.js';
|
|
12
|
+
export type DurableInterpreterOptions = {
|
|
13
|
+
logger?: Logger;
|
|
14
|
+
compiler?: ObservableCompiler;
|
|
15
|
+
contextProvider?: ContextProvider;
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
skipVersoriCredentials?: boolean;
|
|
18
|
+
};
|
|
19
|
+
type Registration = {
|
|
20
|
+
trigger$: Observable<ContextImpl<any, void>>;
|
|
21
|
+
task$: ContextOperatorFunction<any, any, any>;
|
|
22
|
+
localAbortController: AbortController;
|
|
23
|
+
sigintListener: () => void;
|
|
24
|
+
subscription?: Subscription;
|
|
25
|
+
};
|
|
26
|
+
export declare class DurableInterpreter {
|
|
27
|
+
private readonly log;
|
|
28
|
+
private readonly compiler;
|
|
29
|
+
private readonly contextProvider;
|
|
30
|
+
private readonly roundTripperFactory;
|
|
31
|
+
private readonly webhookRouter;
|
|
32
|
+
private readonly cronRouter;
|
|
33
|
+
private cronRegistry;
|
|
34
|
+
private readonly connectionProvider;
|
|
35
|
+
private readonly cronProvider;
|
|
36
|
+
private readonly tracer;
|
|
37
|
+
private readonly cfgReader;
|
|
38
|
+
private readonly queueProvider;
|
|
39
|
+
private readonly otelSDK?;
|
|
40
|
+
private registeredWorkflows;
|
|
41
|
+
private webhookServer?;
|
|
42
|
+
private cronServer?;
|
|
43
|
+
private shutdownServer?;
|
|
44
|
+
private isShuttingDown;
|
|
45
|
+
constructor(log: Logger, compiler: ObservableCompiler, contextProvider: ContextProvider, roundTripperFactory: RoundTripperFactory, webhookRouter: Router, cronRouter: Router, cronRegistry: Map<string, string>, connectionProvider: ConnectionProvider, cronProvider: CronProvider, tracer: Tracer, cfgReader: ConfigReader, queueProvider: QueueAPI, otelSDK?: NodeSDK | undefined);
|
|
46
|
+
static newInstance(options?: DurableInterpreterOptions): Promise<DurableInterpreter>;
|
|
47
|
+
register<O>(workflow: Workflow<O>, options?: DurableInterpreterOptions): Registration;
|
|
48
|
+
start(): Promise<void>;
|
|
49
|
+
stop(): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=DurableInterpreter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DurableInterpreter.d.ts","sourceRoot":"","sources":["../../../../src/src/interpreter/durable/DurableInterpreter.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DurableInterpreter = void 0;
|
|
7
|
+
const api_1 = __importDefault(require("@opentelemetry/api"));
|
|
8
|
+
const exporter_trace_otlp_proto_1 = require("@opentelemetry/exporter-trace-otlp-proto");
|
|
9
|
+
const resources_1 = require("@opentelemetry/resources");
|
|
10
|
+
const sdk_node_1 = require("@opentelemetry/sdk-node");
|
|
11
|
+
const express_1 = __importDefault(require("express"));
|
|
12
|
+
const express_xml_bodyparser_1 = __importDefault(require("express-xml-bodyparser"));
|
|
13
|
+
const rxjs_1 = require("rxjs");
|
|
14
|
+
const ContextProvider_js_1 = require("../../context/ContextProvider.js");
|
|
15
|
+
const default_js_1 = require("../../dsl/http/default.js");
|
|
16
|
+
const constants_js_1 = require("../../dsl/http/versori/constants.js");
|
|
17
|
+
const cronapi_js_1 = require("../../dsl/http/versori/cronapi.js");
|
|
18
|
+
const platformapi_js_1 = require("../../dsl/http/versori/platformapi.js");
|
|
19
|
+
const roundtripper_js_1 = require("../../dsl/http/versori/roundtripper.js");
|
|
20
|
+
const Workflow_js_1 = require("../../dsl/Workflow.js");
|
|
21
|
+
const MemoryKeyValueProvider_js_1 = require("../../kv/memory/MemoryKeyValueProvider.js");
|
|
22
|
+
const NatsKeyValueProvider_js_1 = require("../../kv/nats/NatsKeyValueProvider.js");
|
|
23
|
+
const ConsoleLogger_js_1 = require("../../observability/logging/ConsoleLogger.js");
|
|
24
|
+
const ObservableCompiler_js_1 = require("./ObservableCompiler.js");
|
|
25
|
+
const proxyroundtripper_js_1 = require("../../dsl/http/versori/proxyroundtripper.js");
|
|
26
|
+
const configloader_js_1 = require("../../dsl/http/versori/configloader.js");
|
|
27
|
+
const Queue_js_1 = require("./Queue.js");
|
|
28
|
+
function getKVProvider(runLocal) {
|
|
29
|
+
if (runLocal) {
|
|
30
|
+
return Promise.resolve(new MemoryKeyValueProvider_js_1.MemoryKeyValueProvider());
|
|
31
|
+
}
|
|
32
|
+
return NatsKeyValueProvider_js_1.NatsKeyValueProvider.fromEnv();
|
|
33
|
+
}
|
|
34
|
+
function getRoundTripperFactory(log, tracer, opts) {
|
|
35
|
+
if (opts && opts.runLocal) {
|
|
36
|
+
log.info('Running in local mode, using ProxyRoundTripperFactory');
|
|
37
|
+
return proxyroundtripper_js_1.ProxyRoundTripper.fromEnv(log);
|
|
38
|
+
}
|
|
39
|
+
if (!opts || !opts.skipVersoriCredentials) {
|
|
40
|
+
return roundtripper_js_1.VersoriCredentialsFactory.fromEnv(log, tracer);
|
|
41
|
+
}
|
|
42
|
+
log.info('Running with default round tripper factory');
|
|
43
|
+
return new default_js_1.DefaultRoundTripperFactory();
|
|
44
|
+
}
|
|
45
|
+
class DurableInterpreter {
|
|
46
|
+
constructor(log, compiler, contextProvider, roundTripperFactory, webhookRouter, cronRouter, cronRegistry, connectionProvider, cronProvider, tracer, cfgReader, queueProvider, otelSDK) {
|
|
47
|
+
Object.defineProperty(this, "log", {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
configurable: true,
|
|
50
|
+
writable: true,
|
|
51
|
+
value: log
|
|
52
|
+
});
|
|
53
|
+
Object.defineProperty(this, "compiler", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
configurable: true,
|
|
56
|
+
writable: true,
|
|
57
|
+
value: compiler
|
|
58
|
+
});
|
|
59
|
+
Object.defineProperty(this, "contextProvider", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
configurable: true,
|
|
62
|
+
writable: true,
|
|
63
|
+
value: contextProvider
|
|
64
|
+
});
|
|
65
|
+
Object.defineProperty(this, "roundTripperFactory", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
value: roundTripperFactory
|
|
70
|
+
});
|
|
71
|
+
Object.defineProperty(this, "webhookRouter", {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
configurable: true,
|
|
74
|
+
writable: true,
|
|
75
|
+
value: webhookRouter
|
|
76
|
+
});
|
|
77
|
+
Object.defineProperty(this, "cronRouter", {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
configurable: true,
|
|
80
|
+
writable: true,
|
|
81
|
+
value: cronRouter
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(this, "cronRegistry", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
configurable: true,
|
|
86
|
+
writable: true,
|
|
87
|
+
value: cronRegistry
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(this, "connectionProvider", {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
configurable: true,
|
|
92
|
+
writable: true,
|
|
93
|
+
value: connectionProvider
|
|
94
|
+
});
|
|
95
|
+
Object.defineProperty(this, "cronProvider", {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
configurable: true,
|
|
98
|
+
writable: true,
|
|
99
|
+
value: cronProvider
|
|
100
|
+
});
|
|
101
|
+
Object.defineProperty(this, "tracer", {
|
|
102
|
+
enumerable: true,
|
|
103
|
+
configurable: true,
|
|
104
|
+
writable: true,
|
|
105
|
+
value: tracer
|
|
106
|
+
});
|
|
107
|
+
Object.defineProperty(this, "cfgReader", {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
configurable: true,
|
|
110
|
+
writable: true,
|
|
111
|
+
value: cfgReader
|
|
112
|
+
});
|
|
113
|
+
Object.defineProperty(this, "queueProvider", {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
configurable: true,
|
|
116
|
+
writable: true,
|
|
117
|
+
value: queueProvider
|
|
118
|
+
});
|
|
119
|
+
Object.defineProperty(this, "otelSDK", {
|
|
120
|
+
enumerable: true,
|
|
121
|
+
configurable: true,
|
|
122
|
+
writable: true,
|
|
123
|
+
value: otelSDK
|
|
124
|
+
});
|
|
125
|
+
Object.defineProperty(this, "registeredWorkflows", {
|
|
126
|
+
enumerable: true,
|
|
127
|
+
configurable: true,
|
|
128
|
+
writable: true,
|
|
129
|
+
value: []
|
|
130
|
+
});
|
|
131
|
+
Object.defineProperty(this, "webhookServer", {
|
|
132
|
+
enumerable: true,
|
|
133
|
+
configurable: true,
|
|
134
|
+
writable: true,
|
|
135
|
+
value: void 0
|
|
136
|
+
});
|
|
137
|
+
Object.defineProperty(this, "cronServer", {
|
|
138
|
+
enumerable: true,
|
|
139
|
+
configurable: true,
|
|
140
|
+
writable: true,
|
|
141
|
+
value: void 0
|
|
142
|
+
});
|
|
143
|
+
Object.defineProperty(this, "shutdownServer", {
|
|
144
|
+
enumerable: true,
|
|
145
|
+
configurable: true,
|
|
146
|
+
writable: true,
|
|
147
|
+
value: void 0
|
|
148
|
+
});
|
|
149
|
+
Object.defineProperty(this, "isShuttingDown", {
|
|
150
|
+
enumerable: true,
|
|
151
|
+
configurable: true,
|
|
152
|
+
writable: true,
|
|
153
|
+
value: false
|
|
154
|
+
});
|
|
155
|
+
if (typeof this.log === 'undefined') {
|
|
156
|
+
// this captures the old way of instantiating the DurableInterpreter and provides an
|
|
157
|
+
// error message back to the user to let them know they should use the new way.
|
|
158
|
+
throw new Error('DurableInterpreter should not be instantiated directly. Use DurableInterpreter.newInstance() instead.');
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
static async newInstance(options = {}) {
|
|
162
|
+
const log = options.logger || new ConsoleLogger_js_1.ConsoleLogger('debug');
|
|
163
|
+
const compiler = options.compiler || new ObservableCompiler_js_1.ObservableCompiler();
|
|
164
|
+
const serviceName = Deno.env.get(constants_js_1.envVarProjectId) || 'example-service';
|
|
165
|
+
const environmentID = Deno.env.get(constants_js_1.envVarEnvId) || 'development';
|
|
166
|
+
const version = Deno.env.get(constants_js_1.envVarVersion) || '1.0.0';
|
|
167
|
+
const environment = Deno.env.get(constants_js_1.envVarEnvironmentName) || 'development';
|
|
168
|
+
const orgId = Deno.env.get(constants_js_1.envVarOrgId) || 'development';
|
|
169
|
+
const orgSlug = Deno.env.get(constants_js_1.envVarOrgSlug) || 'development';
|
|
170
|
+
const otelTracesURL = Deno.env.get(constants_js_1.envVarOtelTracesURL);
|
|
171
|
+
let otelSDK;
|
|
172
|
+
const configReader = configloader_js_1.VersoriConfigReader.fromEnv(log);
|
|
173
|
+
const runLocal = Deno.env.get(constants_js_1.envVarLocalRun) === 'true';
|
|
174
|
+
await waitForReady(log);
|
|
175
|
+
// Do NOT change those attributes, they are used by the API to filter on
|
|
176
|
+
const resource = (0, resources_1.resourceFromAttributes)({
|
|
177
|
+
'service.id': serviceName,
|
|
178
|
+
'service.environment': environment,
|
|
179
|
+
'service.environment_id': environmentID,
|
|
180
|
+
'service.version': version,
|
|
181
|
+
'service.organisation_id': orgId,
|
|
182
|
+
'service.organisation_slug': orgSlug,
|
|
183
|
+
});
|
|
184
|
+
if (otelTracesURL && serviceName) {
|
|
185
|
+
otelSDK = new sdk_node_1.NodeSDK({
|
|
186
|
+
traceExporter: new exporter_trace_otlp_proto_1.OTLPTraceExporter({
|
|
187
|
+
url: otelTracesURL,
|
|
188
|
+
}),
|
|
189
|
+
serviceName: serviceName,
|
|
190
|
+
resource: resource,
|
|
191
|
+
});
|
|
192
|
+
log.info('Starting OpenTelemetry SDK');
|
|
193
|
+
otelSDK.start();
|
|
194
|
+
}
|
|
195
|
+
const tracer = api_1.default.trace.getTracer(serviceName, version);
|
|
196
|
+
const roundTripperFactory = getRoundTripperFactory(log, tracer, {
|
|
197
|
+
skipVersoriCredentials: options.skipVersoriCredentials,
|
|
198
|
+
runLocal: runLocal,
|
|
199
|
+
});
|
|
200
|
+
const queueProvider = await Queue_js_1.QueueImpl.fromEnv(log);
|
|
201
|
+
if (options.contextProvider) {
|
|
202
|
+
// no need to set up a key-value provider if options.contextProvider is already
|
|
203
|
+
// initialised.
|
|
204
|
+
return new DurableInterpreter(log, compiler, options.contextProvider, roundTripperFactory, express_1.default.Router(), express_1.default.Router(), new Map(), platformapi_js_1.PlatformAPIClient.fromEnv(), cronapi_js_1.CronAPIClient.fromEnv(), tracer, configReader, queueProvider, otelSDK);
|
|
205
|
+
}
|
|
206
|
+
const kvp = await getKVProvider(runLocal);
|
|
207
|
+
return new DurableInterpreter(log, compiler, new ContextProvider_js_1.ContextProviderImpl(log, kvp, roundTripperFactory.credentials(), queueProvider), roundTripperFactory, express_1.default.Router(), express_1.default.Router(), new Map(), platformapi_js_1.PlatformAPIClient.fromEnv(), cronapi_js_1.CronAPIClient.fromEnv(), tracer, configReader, queueProvider, otelSDK);
|
|
208
|
+
}
|
|
209
|
+
register(workflow, options) {
|
|
210
|
+
const localAbortController = new AbortController();
|
|
211
|
+
const combinedSignal = options?.signal
|
|
212
|
+
? AbortSignal.any([localAbortController.signal, options.signal])
|
|
213
|
+
: localAbortController.signal;
|
|
214
|
+
if (!(workflow instanceof Workflow_js_1.WorkflowImpl)) {
|
|
215
|
+
throw new Error('workflow is not an instance of WorkflowImpl');
|
|
216
|
+
}
|
|
217
|
+
this.log.info('DurableInterpreter.register', { workflow });
|
|
218
|
+
const compilerContext = {
|
|
219
|
+
compiler: this.compiler,
|
|
220
|
+
log: this.log,
|
|
221
|
+
tracer: this.tracer,
|
|
222
|
+
contextProvider: this.contextProvider,
|
|
223
|
+
roundTripperFactory: this.roundTripperFactory,
|
|
224
|
+
webhookRouter: this.webhookRouter,
|
|
225
|
+
queueProvider: this.queueProvider,
|
|
226
|
+
cronRouter: this.cronRouter,
|
|
227
|
+
cronRegistry: this.cronRegistry,
|
|
228
|
+
connectionProvider: this.connectionProvider,
|
|
229
|
+
configReader: this.cfgReader,
|
|
230
|
+
};
|
|
231
|
+
const trigger$ = this.compiler.compileTrigger(compilerContext, workflow.trigger, combinedSignal);
|
|
232
|
+
const task$ = this.compiler.compileTask(compilerContext, workflow.task);
|
|
233
|
+
const registration = {
|
|
234
|
+
trigger$,
|
|
235
|
+
task$,
|
|
236
|
+
localAbortController,
|
|
237
|
+
sigintListener: () => {
|
|
238
|
+
this.log.info('Received SIGINT, shutting down workflow');
|
|
239
|
+
localAbortController.abort();
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
this.registeredWorkflows.push(registration);
|
|
243
|
+
return registration;
|
|
244
|
+
}
|
|
245
|
+
async start() {
|
|
246
|
+
const port = Deno.env.get('PORT') || 3000;
|
|
247
|
+
const cronPort = Deno.env.get('CRON_PORT') || 3001;
|
|
248
|
+
const webhookApp = (0, express_1.default)();
|
|
249
|
+
webhookApp.use(express_1.default.json({ limit: '50mb' })); // Add JSON body parser middleware
|
|
250
|
+
const cronApp = (0, express_1.default)();
|
|
251
|
+
cronApp.use(express_1.default.json());
|
|
252
|
+
const xml2jsDefaults = {
|
|
253
|
+
explicitArray: false,
|
|
254
|
+
normalize: false,
|
|
255
|
+
normalizeTags: false,
|
|
256
|
+
trim: true,
|
|
257
|
+
};
|
|
258
|
+
webhookApp.use((0, express_xml_bodyparser_1.default)(xml2jsDefaults));
|
|
259
|
+
// Add health check route
|
|
260
|
+
this.webhookRouter.get('/health', (_req, res) => {
|
|
261
|
+
res.json({ status: 'healthy' });
|
|
262
|
+
});
|
|
263
|
+
this.cronRouter.get('/health', (_req, res) => {
|
|
264
|
+
res.json({ status: 'healthy' });
|
|
265
|
+
});
|
|
266
|
+
// Add router to the webhookApplication
|
|
267
|
+
webhookApp.use(this.webhookRouter);
|
|
268
|
+
cronApp.use(this.cronRouter);
|
|
269
|
+
// Start all registered workflows
|
|
270
|
+
for (const registration of this.registeredWorkflows) {
|
|
271
|
+
Deno.addSignalListener('SIGINT', registration.sigintListener);
|
|
272
|
+
registration.subscription = registration.trigger$
|
|
273
|
+
.pipe((0, rxjs_1.tap)((ctx) => {
|
|
274
|
+
ctx.log.info('DurableInterpreter.executionStarted', { data: ctx.data });
|
|
275
|
+
}), (0, rxjs_1.mergeMap)((ctx) => (0, rxjs_1.of)(ctx).pipe(registration.task$, (0, rxjs_1.catchError)((err) => {
|
|
276
|
+
ctx.log.error('DurableInterpreter.executionError', {
|
|
277
|
+
error: err instanceof Error ? err.toString() : err,
|
|
278
|
+
});
|
|
279
|
+
try {
|
|
280
|
+
ctx.options.onError?.(ctx.withData(err));
|
|
281
|
+
}
|
|
282
|
+
catch (err) {
|
|
283
|
+
ctx.log.error('DurableInterpreter.onErrorError: failed to call onError handler', { error: err instanceof Error ? err.toString() : err });
|
|
284
|
+
ctx.options.onError?.(ctx.withData({
|
|
285
|
+
message: 'Internal server error',
|
|
286
|
+
error: err instanceof Error ? err.toString() : err,
|
|
287
|
+
}));
|
|
288
|
+
}
|
|
289
|
+
return rxjs_1.EMPTY;
|
|
290
|
+
}))))
|
|
291
|
+
.subscribe({
|
|
292
|
+
next: async (ctx) => {
|
|
293
|
+
const durationMs = Date.now() - ctx.startTime.getTime();
|
|
294
|
+
ctx.log.info('DurableInterpreter.executionCompleted', {
|
|
295
|
+
durationMs,
|
|
296
|
+
data: ctx.data,
|
|
297
|
+
});
|
|
298
|
+
try {
|
|
299
|
+
ctx.options.onSuccess?.(ctx);
|
|
300
|
+
}
|
|
301
|
+
catch (err) {
|
|
302
|
+
ctx.log.error('DurableInterpreter.onSuccessError: failed to call onSuccess handler', { error: err instanceof Error ? err.toString() : err });
|
|
303
|
+
ctx.options.onSuccess?.(ctx.withData({
|
|
304
|
+
message: 'Internal server error',
|
|
305
|
+
error: err instanceof Error ? err.toString() : err,
|
|
306
|
+
}));
|
|
307
|
+
}
|
|
308
|
+
if (ctx.workflowId) {
|
|
309
|
+
this.log.info('Async workflow completed', {
|
|
310
|
+
workflowId: ctx.workflowId,
|
|
311
|
+
});
|
|
312
|
+
const output = ctx.data ? btoa(JSON.stringify(ctx.data)) : undefined;
|
|
313
|
+
await ctx.queue?.complete({
|
|
314
|
+
id: ctx.workflowId,
|
|
315
|
+
output,
|
|
316
|
+
status: 'completed',
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
this.contextProvider.destroy(ctx);
|
|
320
|
+
},
|
|
321
|
+
error: (err) => {
|
|
322
|
+
this.log.error('DurableInterpreter.error', {
|
|
323
|
+
error: err instanceof Error ? err.toString() : err,
|
|
324
|
+
});
|
|
325
|
+
Deno.removeSignalListener('SIGINT', registration.sigintListener);
|
|
326
|
+
},
|
|
327
|
+
complete: () => {
|
|
328
|
+
this.log.info('DurableInterpreter.workflowCompleted');
|
|
329
|
+
Deno.removeSignalListener('SIGINT', registration.sigintListener);
|
|
330
|
+
},
|
|
331
|
+
});
|
|
332
|
+
registration.subscription.add(() => {
|
|
333
|
+
registration.subscription = undefined;
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
try {
|
|
337
|
+
this.cronProvider.updateCrons(this.cronRegistry);
|
|
338
|
+
}
|
|
339
|
+
catch (err) {
|
|
340
|
+
this.log.error('DurableInterpreter.updateCronsError', {
|
|
341
|
+
error: err instanceof Error ? err.toString() : err,
|
|
342
|
+
});
|
|
343
|
+
throw new Error('Unable to register scheduler tasks with central cron provider');
|
|
344
|
+
}
|
|
345
|
+
this.webhookServer = webhookApp.listen(port, () => {
|
|
346
|
+
this.log.info(`Express server listening on port ${port}`);
|
|
347
|
+
});
|
|
348
|
+
this.cronServer = cronApp.listen(cronPort, () => {
|
|
349
|
+
this.log.info(`Cron server listening on port ${cronPort}`);
|
|
350
|
+
});
|
|
351
|
+
this.shutdownServer = () => {
|
|
352
|
+
if (this.isShuttingDown) {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
this.isShuttingDown = true;
|
|
356
|
+
this.log.info('Shutting down server');
|
|
357
|
+
// Close the server
|
|
358
|
+
if (this.webhookServer) {
|
|
359
|
+
this.webhookServer.close();
|
|
360
|
+
}
|
|
361
|
+
if (this.cronServer) {
|
|
362
|
+
this.cronServer.close();
|
|
363
|
+
}
|
|
364
|
+
// Remove all signal listeners
|
|
365
|
+
for (const registration of this.registeredWorkflows) {
|
|
366
|
+
Deno.removeSignalListener('SIGINT', registration.sigintListener);
|
|
367
|
+
// Unsubscribe from all observables
|
|
368
|
+
if (registration.subscription) {
|
|
369
|
+
registration.subscription.unsubscribe();
|
|
370
|
+
}
|
|
371
|
+
// Abort all controllers
|
|
372
|
+
registration.localAbortController.abort();
|
|
373
|
+
}
|
|
374
|
+
// Remove the server shutdown listener
|
|
375
|
+
if (this.shutdownServer) {
|
|
376
|
+
Deno.removeSignalListener('SIGINT', this.shutdownServer);
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
Deno.addSignalListener('SIGINT', this.shutdownServer);
|
|
380
|
+
return new Promise((resolve) => {
|
|
381
|
+
let serversClosed = 0;
|
|
382
|
+
const totalServers = [this.webhookServer, this.cronServer].filter(Boolean).length;
|
|
383
|
+
const checkResolve = () => {
|
|
384
|
+
serversClosed++;
|
|
385
|
+
if (serversClosed === totalServers) {
|
|
386
|
+
this.log.info('All servers closed');
|
|
387
|
+
resolve();
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
if (this.webhookServer) {
|
|
391
|
+
this.webhookServer.on('close', () => {
|
|
392
|
+
this.log.info('Webhook server closed');
|
|
393
|
+
checkResolve();
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
if (this.cronServer) {
|
|
397
|
+
this.cronServer.on('close', () => {
|
|
398
|
+
this.log.info('Cron server closed');
|
|
399
|
+
checkResolve();
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
if (!this.webhookServer && !this.cronServer) {
|
|
403
|
+
resolve();
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
async stop() {
|
|
408
|
+
this.otelSDK?.shutdown();
|
|
409
|
+
if (this.shutdownServer) {
|
|
410
|
+
this.shutdownServer();
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
exports.DurableInterpreter = DurableInterpreter;
|
|
415
|
+
async function waitForReady(log) {
|
|
416
|
+
const readyCheckUrl = Deno.env.get('READY_CHECK_URL');
|
|
417
|
+
if (!readyCheckUrl) {
|
|
418
|
+
return Promise.resolve();
|
|
419
|
+
}
|
|
420
|
+
const maxAttempts = 40; // should be 20 seconds
|
|
421
|
+
const delay = 500;
|
|
422
|
+
log.info('DurableInterpreter.waitForReady: waiting for network to be ready', { readyCheckUrl });
|
|
423
|
+
for (let i = 0; i < maxAttempts; i++) {
|
|
424
|
+
try {
|
|
425
|
+
const response = await fetch(readyCheckUrl);
|
|
426
|
+
if (response.ok) {
|
|
427
|
+
log.info('DurableInterpreter.waitForReady: network is ready');
|
|
428
|
+
return Promise.resolve();
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
catch (err) {
|
|
432
|
+
log.error('DurableInterpreter.waitForReadyError', {
|
|
433
|
+
error: err instanceof Error ? err.toString() : err,
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
log.info('DurableInterpreter.waitForReady: retrying...', { attempt: i });
|
|
437
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
438
|
+
}
|
|
439
|
+
throw new Error(`Network is not ready after ${maxAttempts * (delay / 1000)} seconds`);
|
|
440
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExecutionError.d.ts","sourceRoot":"","sources":["../../../../src/src/interpreter/durable/ExecutionError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnD,qBAAa,cAAe,SAAQ,KAAK;IACrC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;gBAEN,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;CAMtE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExecutionError = void 0;
|
|
4
|
+
class ExecutionError extends Error {
|
|
5
|
+
constructor(ctx, message, opts) {
|
|
6
|
+
super(message, opts);
|
|
7
|
+
Object.defineProperty(this, "ctx", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value: void 0
|
|
12
|
+
});
|
|
13
|
+
this.name = 'ExecutionError';
|
|
14
|
+
this.ctx = ctx;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.ExecutionError = ExecutionError;
|