@acmekit/workflow-engine-inmemory 2.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/loaders/index.d.ts +2 -0
- package/dist/loaders/index.d.ts.map +1 -0
- package/dist/loaders/index.js +9 -0
- package/dist/loaders/index.js.map +1 -0
- package/dist/loaders/utils.d.ts +5 -0
- package/dist/loaders/utils.d.ts.map +1 -0
- package/dist/loaders/utils.js +10 -0
- package/dist/loaders/utils.js.map +1 -0
- package/dist/migrations/Migration20231228143900.d.ts +6 -0
- package/dist/migrations/Migration20231228143900.d.ts.map +1 -0
- package/dist/migrations/Migration20231228143900.js +40 -0
- package/dist/migrations/Migration20231228143900.js.map +1 -0
- package/dist/migrations/Migration20241206101446.d.ts +5 -0
- package/dist/migrations/Migration20241206101446.d.ts.map +1 -0
- package/dist/migrations/Migration20241206101446.js +19 -0
- package/dist/migrations/Migration20241206101446.js.map +1 -0
- package/dist/migrations/Migration20250128174331.d.ts +6 -0
- package/dist/migrations/Migration20250128174331.d.ts.map +1 -0
- package/dist/migrations/Migration20250128174331.js +24 -0
- package/dist/migrations/Migration20250128174331.js.map +1 -0
- package/dist/migrations/Migration20250505092459.d.ts +6 -0
- package/dist/migrations/Migration20250505092459.d.ts.map +1 -0
- package/dist/migrations/Migration20250505092459.js +40 -0
- package/dist/migrations/Migration20250505092459.js.map +1 -0
- package/dist/migrations/Migration20250819104213.d.ts +6 -0
- package/dist/migrations/Migration20250819104213.d.ts.map +1 -0
- package/dist/migrations/Migration20250819104213.js +14 -0
- package/dist/migrations/Migration20250819104213.js.map +1 -0
- package/dist/migrations/Migration20250819110924.d.ts +6 -0
- package/dist/migrations/Migration20250819110924.d.ts.map +1 -0
- package/dist/migrations/Migration20250819110924.js +16 -0
- package/dist/migrations/Migration20250819110924.js.map +1 -0
- package/dist/migrations/Migration20250908080305.d.ts +6 -0
- package/dist/migrations/Migration20250908080305.d.ts.map +1 -0
- package/dist/migrations/Migration20250908080305.js +20 -0
- package/dist/migrations/Migration20250908080305.js.map +1 -0
- package/dist/models/index.d.ts +2 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +6 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/workflow-execution.d.ts +12 -0
- package/dist/models/workflow-execution.d.ts.map +1 -0
- package/dist/models/workflow-execution.js +60 -0
- package/dist/models/workflow-execution.js.map +1 -0
- package/dist/schema/index.d.ts +3 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +27 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +19 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/workflow-orchestrator.d.ts +86 -0
- package/dist/services/workflow-orchestrator.d.ts.map +1 -0
- package/dist/services/workflow-orchestrator.js +563 -0
- package/dist/services/workflow-orchestrator.js.map +1 -0
- package/dist/services/workflows-module.d.ts +163 -0
- package/dist/services/workflows-module.d.ts.map +1 -0
- package/dist/services/workflows-module.js +208 -0
- package/dist/services/workflows-module.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +18 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/workflow-orchestrator-storage.d.ts +43 -0
- package/dist/utils/workflow-orchestrator-storage.d.ts.map +1 -0
- package/dist/utils/workflow-orchestrator-storage.js +541 -0
- package/dist/utils/workflow-orchestrator-storage.js.map +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { DistributedTransactionEvents, DistributedTransactionType, TransactionStep } from "@acmekit/framework/orchestration";
|
|
2
|
+
import { ContainerLike, Context, AcmeKitContainer } from "@acmekit/framework/types";
|
|
3
|
+
import { TransactionState } from "@acmekit/framework/utils";
|
|
4
|
+
import { type FlowRunOptions, ReturnWorkflow } from "@acmekit/framework/workflows-sdk";
|
|
5
|
+
import { WorkflowOrchestratorCancelOptions } from "../types";
|
|
6
|
+
import { InMemoryDistributedTransactionStorage } from "../utils";
|
|
7
|
+
export type WorkflowOrchestratorRunOptions<T> = Omit<FlowRunOptions<T>, "container"> & {
|
|
8
|
+
transactionId?: string;
|
|
9
|
+
runId?: string;
|
|
10
|
+
container?: ContainerLike;
|
|
11
|
+
};
|
|
12
|
+
type RegisterStepSuccessOptions<T> = Omit<WorkflowOrchestratorRunOptions<T>, "transactionId" | "input">;
|
|
13
|
+
type RegisterStepFailureOptions<T> = Omit<WorkflowOrchestratorRunOptions<T>, "transactionId" | "input"> & {
|
|
14
|
+
forcePermanentFailure?: boolean;
|
|
15
|
+
};
|
|
16
|
+
type RetryStepOptions<T> = Omit<WorkflowOrchestratorRunOptions<T>, "transactionId" | "input" | "resultFrom">;
|
|
17
|
+
type IdempotencyKeyParts = {
|
|
18
|
+
workflowId: string;
|
|
19
|
+
transactionId: string;
|
|
20
|
+
stepId: string;
|
|
21
|
+
action: "invoke" | "compensate";
|
|
22
|
+
};
|
|
23
|
+
type NotifyOptions = {
|
|
24
|
+
eventType: keyof DistributedTransactionEvents;
|
|
25
|
+
workflowId: string;
|
|
26
|
+
transactionId?: string;
|
|
27
|
+
state?: TransactionState;
|
|
28
|
+
step?: TransactionStep;
|
|
29
|
+
response?: unknown;
|
|
30
|
+
result?: unknown;
|
|
31
|
+
errors?: unknown[];
|
|
32
|
+
};
|
|
33
|
+
type SubscriberHandler = {
|
|
34
|
+
(input: NotifyOptions): void;
|
|
35
|
+
} & {
|
|
36
|
+
_id?: string;
|
|
37
|
+
};
|
|
38
|
+
type SubscribeOptions = {
|
|
39
|
+
workflowId: string;
|
|
40
|
+
transactionId?: string;
|
|
41
|
+
subscriber: SubscriberHandler;
|
|
42
|
+
subscriberId?: string;
|
|
43
|
+
};
|
|
44
|
+
type UnsubscribeOptions = {
|
|
45
|
+
workflowId: string;
|
|
46
|
+
transactionId?: string;
|
|
47
|
+
subscriberOrId: string | SubscriberHandler;
|
|
48
|
+
};
|
|
49
|
+
export declare class WorkflowOrchestratorService {
|
|
50
|
+
#private;
|
|
51
|
+
private static subscribers;
|
|
52
|
+
private container_;
|
|
53
|
+
private inMemoryDistributedTransactionStorage_;
|
|
54
|
+
constructor({ inMemoryDistributedTransactionStorage, sharedContainer, }: {
|
|
55
|
+
inMemoryDistributedTransactionStorage: InMemoryDistributedTransactionStorage;
|
|
56
|
+
sharedContainer: AcmeKitContainer;
|
|
57
|
+
});
|
|
58
|
+
onApplicationStart(): Promise<void>;
|
|
59
|
+
onApplicationShutdown(): Promise<void>;
|
|
60
|
+
private triggerParentStep;
|
|
61
|
+
run<T = unknown>(workflowIdOrWorkflow: string | ReturnWorkflow<any, any, any>, options?: WorkflowOrchestratorRunOptions<T>): Promise<any>;
|
|
62
|
+
cancel(workflowIdOrWorkflow: string | ReturnWorkflow<any, any, any>, options?: WorkflowOrchestratorCancelOptions): Promise<any>;
|
|
63
|
+
getRunningTransaction(workflowId: string, transactionId: string, context?: Context): Promise<DistributedTransactionType>;
|
|
64
|
+
retryStep<T = unknown>({ idempotencyKey, options, }: {
|
|
65
|
+
idempotencyKey: string | IdempotencyKeyParts;
|
|
66
|
+
options?: RetryStepOptions<T>;
|
|
67
|
+
}): Promise<any>;
|
|
68
|
+
setStepSuccess<T = unknown>({ idempotencyKey, stepResponse, options, }: {
|
|
69
|
+
idempotencyKey: string | IdempotencyKeyParts;
|
|
70
|
+
stepResponse: unknown;
|
|
71
|
+
options?: RegisterStepSuccessOptions<T>;
|
|
72
|
+
}): Promise<any>;
|
|
73
|
+
setStepFailure<T = unknown>({ idempotencyKey, stepResponse, options, }: {
|
|
74
|
+
idempotencyKey: string | IdempotencyKeyParts;
|
|
75
|
+
stepResponse: unknown;
|
|
76
|
+
options?: RegisterStepFailureOptions<T>;
|
|
77
|
+
}): Promise<any>;
|
|
78
|
+
subscribe({ workflowId, transactionId, subscriber, subscriberId, }: SubscribeOptions): void;
|
|
79
|
+
unsubscribe({ workflowId, transactionId, subscriberOrId, }: UnsubscribeOptions): void;
|
|
80
|
+
private notify;
|
|
81
|
+
private processSubscriberNotifications;
|
|
82
|
+
private buildWorkflowEvents;
|
|
83
|
+
private buildIdempotencyKeyAndParts;
|
|
84
|
+
}
|
|
85
|
+
export {};
|
|
86
|
+
//# sourceMappingURL=workflow-orchestrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-orchestrator.d.ts","sourceRoot":"","sources":["../../src/services/workflow-orchestrator.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _WorkflowOrchestratorService_logger;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.WorkflowOrchestratorService = void 0;
|
|
16
|
+
const orchestration_1 = require("@acmekit/framework/orchestration");
|
|
17
|
+
const utils_1 = require("@acmekit/framework/utils");
|
|
18
|
+
const workflows_sdk_1 = require("@acmekit/framework/workflows-sdk");
|
|
19
|
+
const ulid_1 = require("ulid");
|
|
20
|
+
const AnySubscriber = "any";
|
|
21
|
+
class WorkflowOrchestratorService {
|
|
22
|
+
constructor({ inMemoryDistributedTransactionStorage, sharedContainer, }) {
|
|
23
|
+
_WorkflowOrchestratorService_logger.set(this, void 0);
|
|
24
|
+
this.container_ = sharedContainer;
|
|
25
|
+
this.inMemoryDistributedTransactionStorage_ =
|
|
26
|
+
inMemoryDistributedTransactionStorage;
|
|
27
|
+
__classPrivateFieldSet(this, _WorkflowOrchestratorService_logger, this.container_.resolve("logger", { allowUnregistered: true }) ?? console, "f");
|
|
28
|
+
inMemoryDistributedTransactionStorage.setWorkflowOrchestratorService(this);
|
|
29
|
+
orchestration_1.DistributedTransaction.setStorage(inMemoryDistributedTransactionStorage);
|
|
30
|
+
orchestration_1.WorkflowScheduler.setStorage(inMemoryDistributedTransactionStorage);
|
|
31
|
+
}
|
|
32
|
+
async onApplicationStart() {
|
|
33
|
+
await this.inMemoryDistributedTransactionStorage_.onApplicationStart();
|
|
34
|
+
}
|
|
35
|
+
async onApplicationShutdown() {
|
|
36
|
+
await this.inMemoryDistributedTransactionStorage_.onApplicationShutdown();
|
|
37
|
+
}
|
|
38
|
+
async triggerParentStep(transaction, result, errors) {
|
|
39
|
+
const metadata = transaction.flow.metadata;
|
|
40
|
+
const { parentStepIdempotencyKey, cancelingFromParentStep } = metadata ?? {};
|
|
41
|
+
if (cancelingFromParentStep) {
|
|
42
|
+
/**
|
|
43
|
+
* If the sub workflow is cancelling from a parent step, we don't want to trigger the parent
|
|
44
|
+
* step.
|
|
45
|
+
*/
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (parentStepIdempotencyKey) {
|
|
49
|
+
const hasFailed = [
|
|
50
|
+
utils_1.TransactionState.REVERTED,
|
|
51
|
+
utils_1.TransactionState.FAILED,
|
|
52
|
+
].includes(transaction.flow.state);
|
|
53
|
+
if (hasFailed) {
|
|
54
|
+
await this.setStepFailure({
|
|
55
|
+
idempotencyKey: parentStepIdempotencyKey,
|
|
56
|
+
stepResponse: errors,
|
|
57
|
+
options: {
|
|
58
|
+
logOnError: true,
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
await this.setStepSuccess({
|
|
64
|
+
idempotencyKey: parentStepIdempotencyKey,
|
|
65
|
+
stepResponse: result,
|
|
66
|
+
options: {
|
|
67
|
+
logOnError: true,
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async run(workflowIdOrWorkflow, options) {
|
|
74
|
+
const { input, transactionId, resultFrom, logOnError, events: eventHandlers, container, } = options ?? {};
|
|
75
|
+
let { throwOnError, context } = options ?? {};
|
|
76
|
+
throwOnError ??= true;
|
|
77
|
+
context ??= {};
|
|
78
|
+
context.transactionId = transactionId ?? "auto-" + (0, ulid_1.ulid)();
|
|
79
|
+
const workflowId = (0, utils_1.isString)(workflowIdOrWorkflow)
|
|
80
|
+
? workflowIdOrWorkflow
|
|
81
|
+
: workflowIdOrWorkflow.getName();
|
|
82
|
+
if (!workflowId) {
|
|
83
|
+
throw new utils_1.AcmeKitError(utils_1.AcmeKitError.Types.NOT_FOUND, `Workflow ID is required`);
|
|
84
|
+
}
|
|
85
|
+
const events = this.buildWorkflowEvents({
|
|
86
|
+
customEventHandlers: eventHandlers,
|
|
87
|
+
workflowId,
|
|
88
|
+
transactionId: context.transactionId,
|
|
89
|
+
});
|
|
90
|
+
const exportedWorkflow = workflows_sdk_1.AcmeKitWorkflow.getWorkflow(workflowId);
|
|
91
|
+
if (!exportedWorkflow) {
|
|
92
|
+
throw new utils_1.AcmeKitError(utils_1.AcmeKitError.Types.NOT_FOUND, `Workflow with id "${workflowId}" not found.`);
|
|
93
|
+
}
|
|
94
|
+
const ret = await exportedWorkflow.run({
|
|
95
|
+
input,
|
|
96
|
+
throwOnError: false,
|
|
97
|
+
logOnError,
|
|
98
|
+
resultFrom,
|
|
99
|
+
context,
|
|
100
|
+
events,
|
|
101
|
+
container: container ?? this.container_,
|
|
102
|
+
});
|
|
103
|
+
const hasFinished = ret.transaction.hasFinished();
|
|
104
|
+
const metadata = ret.transaction.getFlow().metadata;
|
|
105
|
+
const { parentStepIdempotencyKey } = metadata ?? {};
|
|
106
|
+
const hasFailed = [
|
|
107
|
+
utils_1.TransactionState.REVERTED,
|
|
108
|
+
utils_1.TransactionState.FAILED,
|
|
109
|
+
].includes(ret.transaction.getFlow().state);
|
|
110
|
+
const acknowledgement = {
|
|
111
|
+
transactionId: context.transactionId,
|
|
112
|
+
workflowId: workflowId,
|
|
113
|
+
parentStepIdempotencyKey,
|
|
114
|
+
hasFinished,
|
|
115
|
+
hasFailed,
|
|
116
|
+
};
|
|
117
|
+
if (ret.transaction.hasFinished()) {
|
|
118
|
+
const { result, errors } = ret;
|
|
119
|
+
this.notify({
|
|
120
|
+
eventType: "onFinish",
|
|
121
|
+
workflowId,
|
|
122
|
+
transactionId: context.transactionId,
|
|
123
|
+
state: ret.transaction.getFlow().state,
|
|
124
|
+
result,
|
|
125
|
+
errors,
|
|
126
|
+
});
|
|
127
|
+
await this.triggerParentStep(ret.transaction, result, errors);
|
|
128
|
+
}
|
|
129
|
+
if (throwOnError && (ret.thrownError || ret.errors?.length)) {
|
|
130
|
+
if (ret.thrownError) {
|
|
131
|
+
throw ret.thrownError;
|
|
132
|
+
}
|
|
133
|
+
throw ret.errors[0].error;
|
|
134
|
+
}
|
|
135
|
+
return { acknowledgement, ...ret };
|
|
136
|
+
}
|
|
137
|
+
async cancel(workflowIdOrWorkflow, options) {
|
|
138
|
+
const { transactionId, logOnError, events: eventHandlers, container, } = options ?? {};
|
|
139
|
+
let { throwOnError, context } = options ?? {};
|
|
140
|
+
throwOnError ??= true;
|
|
141
|
+
context ??= {};
|
|
142
|
+
const workflowId = (0, utils_1.isString)(workflowIdOrWorkflow)
|
|
143
|
+
? workflowIdOrWorkflow
|
|
144
|
+
: workflowIdOrWorkflow.getName();
|
|
145
|
+
if (!workflowId) {
|
|
146
|
+
throw new Error("Workflow ID is required");
|
|
147
|
+
}
|
|
148
|
+
if (!transactionId) {
|
|
149
|
+
throw new Error("Transaction ID is required");
|
|
150
|
+
}
|
|
151
|
+
const events = this.buildWorkflowEvents({
|
|
152
|
+
customEventHandlers: eventHandlers,
|
|
153
|
+
workflowId,
|
|
154
|
+
transactionId: transactionId,
|
|
155
|
+
});
|
|
156
|
+
const exportedWorkflow = workflows_sdk_1.AcmeKitWorkflow.getWorkflow(workflowId);
|
|
157
|
+
if (!exportedWorkflow) {
|
|
158
|
+
throw new Error(`Workflow with id "${workflowId}" not found.`);
|
|
159
|
+
}
|
|
160
|
+
const transaction = await this.getRunningTransaction(workflowId, transactionId, {
|
|
161
|
+
...options,
|
|
162
|
+
isCancelling: true,
|
|
163
|
+
});
|
|
164
|
+
if (!transaction) {
|
|
165
|
+
if (!throwOnError) {
|
|
166
|
+
return {
|
|
167
|
+
acknowledgement: {
|
|
168
|
+
transactionId,
|
|
169
|
+
workflowId,
|
|
170
|
+
exists: false,
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
throw new Error("Transaction not found");
|
|
175
|
+
}
|
|
176
|
+
const ret = await exportedWorkflow.cancel({
|
|
177
|
+
transaction,
|
|
178
|
+
throwOnError: false,
|
|
179
|
+
logOnError,
|
|
180
|
+
context,
|
|
181
|
+
events,
|
|
182
|
+
container: container ?? this.container_,
|
|
183
|
+
});
|
|
184
|
+
const hasFinished = ret.transaction.hasFinished();
|
|
185
|
+
const metadata = ret.transaction.getFlow().metadata;
|
|
186
|
+
const { parentStepIdempotencyKey } = metadata ?? {};
|
|
187
|
+
const transactionState = ret.transaction.getFlow().state;
|
|
188
|
+
const hasFailed = [utils_1.TransactionState.FAILED].includes(transactionState);
|
|
189
|
+
const acknowledgement = {
|
|
190
|
+
transactionId: transaction.transactionId,
|
|
191
|
+
workflowId: workflowId,
|
|
192
|
+
parentStepIdempotencyKey,
|
|
193
|
+
hasFinished,
|
|
194
|
+
hasFailed,
|
|
195
|
+
exists: true,
|
|
196
|
+
};
|
|
197
|
+
if (hasFinished) {
|
|
198
|
+
const { result, errors } = ret;
|
|
199
|
+
this.notify({
|
|
200
|
+
eventType: "onFinish",
|
|
201
|
+
workflowId,
|
|
202
|
+
transactionId: transaction.transactionId,
|
|
203
|
+
state: transactionState,
|
|
204
|
+
result,
|
|
205
|
+
errors,
|
|
206
|
+
});
|
|
207
|
+
await this.triggerParentStep(ret.transaction, result, errors);
|
|
208
|
+
}
|
|
209
|
+
if (throwOnError && (ret.thrownError || ret.errors?.length)) {
|
|
210
|
+
if (ret.thrownError) {
|
|
211
|
+
throw ret.thrownError;
|
|
212
|
+
}
|
|
213
|
+
throw ret.errors[0].error;
|
|
214
|
+
}
|
|
215
|
+
return { acknowledgement, ...ret };
|
|
216
|
+
}
|
|
217
|
+
async getRunningTransaction(workflowId, transactionId, context) {
|
|
218
|
+
if (!workflowId) {
|
|
219
|
+
throw new Error("Workflow ID is required");
|
|
220
|
+
}
|
|
221
|
+
if (!transactionId) {
|
|
222
|
+
throw new Error("TransactionId ID is required");
|
|
223
|
+
}
|
|
224
|
+
context ??= {};
|
|
225
|
+
context.transactionId ??= transactionId;
|
|
226
|
+
const exportedWorkflow = workflows_sdk_1.AcmeKitWorkflow.getWorkflow(workflowId);
|
|
227
|
+
if (!exportedWorkflow) {
|
|
228
|
+
throw new Error(`Workflow with id "${workflowId}" not found.`);
|
|
229
|
+
}
|
|
230
|
+
const flow = exportedWorkflow();
|
|
231
|
+
const transaction = await flow.getRunningTransaction(transactionId, context);
|
|
232
|
+
return transaction;
|
|
233
|
+
}
|
|
234
|
+
async retryStep({ idempotencyKey, options, }) {
|
|
235
|
+
const { context, logOnError, container, events: eventHandlers, } = options ?? {};
|
|
236
|
+
let { throwOnError } = options ?? {};
|
|
237
|
+
throwOnError ??= true;
|
|
238
|
+
const [idempotencyKey_, { workflowId, transactionId }] = this.buildIdempotencyKeyAndParts(idempotencyKey);
|
|
239
|
+
const exportedWorkflow = workflows_sdk_1.AcmeKitWorkflow.getWorkflow(workflowId);
|
|
240
|
+
if (!exportedWorkflow) {
|
|
241
|
+
throw new Error(`Workflow with id "${workflowId}" not found.`);
|
|
242
|
+
}
|
|
243
|
+
const events = this.buildWorkflowEvents({
|
|
244
|
+
customEventHandlers: eventHandlers,
|
|
245
|
+
transactionId,
|
|
246
|
+
workflowId,
|
|
247
|
+
});
|
|
248
|
+
const ret = await exportedWorkflow.retryStep({
|
|
249
|
+
idempotencyKey: idempotencyKey_,
|
|
250
|
+
context,
|
|
251
|
+
throwOnError: false,
|
|
252
|
+
logOnError,
|
|
253
|
+
events,
|
|
254
|
+
container: container ?? this.container_,
|
|
255
|
+
});
|
|
256
|
+
if (ret.transaction.hasFinished()) {
|
|
257
|
+
const { result, errors } = ret;
|
|
258
|
+
this.notify({
|
|
259
|
+
eventType: "onFinish",
|
|
260
|
+
workflowId,
|
|
261
|
+
transactionId,
|
|
262
|
+
state: ret.transaction.getFlow().state,
|
|
263
|
+
result,
|
|
264
|
+
errors,
|
|
265
|
+
});
|
|
266
|
+
await this.triggerParentStep(ret.transaction, result, errors);
|
|
267
|
+
}
|
|
268
|
+
if (throwOnError && (ret.thrownError || ret.errors?.length)) {
|
|
269
|
+
if (ret.thrownError) {
|
|
270
|
+
throw ret.thrownError;
|
|
271
|
+
}
|
|
272
|
+
throw ret.errors[0].error;
|
|
273
|
+
}
|
|
274
|
+
return ret;
|
|
275
|
+
}
|
|
276
|
+
async setStepSuccess({ idempotencyKey, stepResponse, options, }) {
|
|
277
|
+
const { context, logOnError, resultFrom, container, events: eventHandlers, } = options ?? {};
|
|
278
|
+
let { throwOnError } = options ?? {};
|
|
279
|
+
throwOnError ??= true;
|
|
280
|
+
const [idempotencyKey_, { workflowId, transactionId }] = this.buildIdempotencyKeyAndParts(idempotencyKey);
|
|
281
|
+
const exportedWorkflow = workflows_sdk_1.AcmeKitWorkflow.getWorkflow(workflowId);
|
|
282
|
+
if (!exportedWorkflow) {
|
|
283
|
+
throw new Error(`Workflow with id "${workflowId}" not found.`);
|
|
284
|
+
}
|
|
285
|
+
const events = this.buildWorkflowEvents({
|
|
286
|
+
customEventHandlers: eventHandlers,
|
|
287
|
+
transactionId,
|
|
288
|
+
workflowId,
|
|
289
|
+
});
|
|
290
|
+
const ret = await exportedWorkflow.registerStepSuccess({
|
|
291
|
+
idempotencyKey: idempotencyKey_,
|
|
292
|
+
context,
|
|
293
|
+
resultFrom,
|
|
294
|
+
throwOnError: false,
|
|
295
|
+
logOnError,
|
|
296
|
+
events,
|
|
297
|
+
response: stepResponse,
|
|
298
|
+
container: container ?? this.container_,
|
|
299
|
+
});
|
|
300
|
+
if (ret.transaction.hasFinished()) {
|
|
301
|
+
const { result, errors } = ret;
|
|
302
|
+
this.notify({
|
|
303
|
+
eventType: "onFinish",
|
|
304
|
+
workflowId,
|
|
305
|
+
transactionId,
|
|
306
|
+
state: ret.transaction.getFlow().state,
|
|
307
|
+
result,
|
|
308
|
+
errors,
|
|
309
|
+
});
|
|
310
|
+
await this.triggerParentStep(ret.transaction, result, errors);
|
|
311
|
+
}
|
|
312
|
+
if (throwOnError && (ret.thrownError || ret.errors?.length)) {
|
|
313
|
+
if (ret.thrownError) {
|
|
314
|
+
throw ret.thrownError;
|
|
315
|
+
}
|
|
316
|
+
throw ret.errors[0].error;
|
|
317
|
+
}
|
|
318
|
+
return ret;
|
|
319
|
+
}
|
|
320
|
+
async setStepFailure({ idempotencyKey, stepResponse, options, }) {
|
|
321
|
+
const { context, logOnError, resultFrom, container, events: eventHandlers, forcePermanentFailure = false, } = options ?? {};
|
|
322
|
+
let { throwOnError } = options ?? {};
|
|
323
|
+
throwOnError ??= true;
|
|
324
|
+
const [idempotencyKey_, { workflowId, transactionId }] = this.buildIdempotencyKeyAndParts(idempotencyKey);
|
|
325
|
+
const exportedWorkflow = workflows_sdk_1.AcmeKitWorkflow.getWorkflow(workflowId);
|
|
326
|
+
if (!exportedWorkflow) {
|
|
327
|
+
throw new Error(`Workflow with id "${workflowId}" not found.`);
|
|
328
|
+
}
|
|
329
|
+
const events = this.buildWorkflowEvents({
|
|
330
|
+
customEventHandlers: eventHandlers,
|
|
331
|
+
transactionId,
|
|
332
|
+
workflowId,
|
|
333
|
+
});
|
|
334
|
+
const ret = await exportedWorkflow.registerStepFailure({
|
|
335
|
+
idempotencyKey: idempotencyKey_,
|
|
336
|
+
context,
|
|
337
|
+
resultFrom,
|
|
338
|
+
throwOnError: false,
|
|
339
|
+
logOnError,
|
|
340
|
+
events,
|
|
341
|
+
forcePermanentFailure,
|
|
342
|
+
response: stepResponse,
|
|
343
|
+
container: container ?? this.container_,
|
|
344
|
+
});
|
|
345
|
+
if (ret.transaction.hasFinished()) {
|
|
346
|
+
const { result, errors } = ret;
|
|
347
|
+
this.notify({
|
|
348
|
+
eventType: "onFinish",
|
|
349
|
+
workflowId,
|
|
350
|
+
transactionId,
|
|
351
|
+
state: ret.transaction.getFlow().state,
|
|
352
|
+
result,
|
|
353
|
+
errors,
|
|
354
|
+
});
|
|
355
|
+
await this.triggerParentStep(ret.transaction, result, errors);
|
|
356
|
+
}
|
|
357
|
+
if (throwOnError && (ret.thrownError || ret.errors?.length)) {
|
|
358
|
+
if (ret.thrownError) {
|
|
359
|
+
throw ret.thrownError;
|
|
360
|
+
}
|
|
361
|
+
throw ret.errors[0].error;
|
|
362
|
+
}
|
|
363
|
+
return ret;
|
|
364
|
+
}
|
|
365
|
+
subscribe({ workflowId, transactionId, subscriber, subscriberId, }) {
|
|
366
|
+
subscriber._id = subscriberId;
|
|
367
|
+
const subscribers = WorkflowOrchestratorService.subscribers.get(workflowId) ?? new Map();
|
|
368
|
+
const handlerIndex = (handlers) => {
|
|
369
|
+
return handlers.findIndex((s) => s === subscriber || s._id === subscriberId);
|
|
370
|
+
};
|
|
371
|
+
if (transactionId) {
|
|
372
|
+
const transactionSubscribers = subscribers.get(transactionId) ?? [];
|
|
373
|
+
const subscriberIndex = handlerIndex(transactionSubscribers);
|
|
374
|
+
if (subscriberIndex !== -1) {
|
|
375
|
+
transactionSubscribers.splice(subscriberIndex, 1);
|
|
376
|
+
}
|
|
377
|
+
transactionSubscribers.push(subscriber);
|
|
378
|
+
subscribers.set(transactionId, transactionSubscribers);
|
|
379
|
+
WorkflowOrchestratorService.subscribers.set(workflowId, subscribers);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
const workflowSubscribers = subscribers.get(AnySubscriber) ?? [];
|
|
383
|
+
const subscriberIndex = handlerIndex(workflowSubscribers);
|
|
384
|
+
if (subscriberIndex !== -1) {
|
|
385
|
+
workflowSubscribers.splice(subscriberIndex, 1);
|
|
386
|
+
}
|
|
387
|
+
workflowSubscribers.push(subscriber);
|
|
388
|
+
subscribers.set(AnySubscriber, workflowSubscribers);
|
|
389
|
+
WorkflowOrchestratorService.subscribers.set(workflowId, subscribers);
|
|
390
|
+
}
|
|
391
|
+
unsubscribe({ workflowId, transactionId, subscriberOrId, }) {
|
|
392
|
+
const subscribers = WorkflowOrchestratorService.subscribers.get(workflowId) ?? new Map();
|
|
393
|
+
const filterSubscribers = (handlers) => {
|
|
394
|
+
return handlers.filter((handler) => {
|
|
395
|
+
return handler._id
|
|
396
|
+
? handler._id !== subscriberOrId
|
|
397
|
+
: handler !== subscriberOrId;
|
|
398
|
+
});
|
|
399
|
+
};
|
|
400
|
+
if (transactionId) {
|
|
401
|
+
const transactionSubscribers = subscribers.get(transactionId) ?? [];
|
|
402
|
+
const newTransactionSubscribers = filterSubscribers(transactionSubscribers);
|
|
403
|
+
if (newTransactionSubscribers.length) {
|
|
404
|
+
subscribers.set(transactionId, newTransactionSubscribers);
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
subscribers.delete(transactionId);
|
|
408
|
+
}
|
|
409
|
+
WorkflowOrchestratorService.subscribers.set(workflowId, subscribers);
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
const workflowSubscribers = subscribers.get(AnySubscriber) ?? [];
|
|
413
|
+
const newWorkflowSubscribers = filterSubscribers(workflowSubscribers);
|
|
414
|
+
if (newWorkflowSubscribers.length) {
|
|
415
|
+
subscribers.set(AnySubscriber, newWorkflowSubscribers);
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
subscribers.delete(AnySubscriber);
|
|
419
|
+
}
|
|
420
|
+
WorkflowOrchestratorService.subscribers.set(workflowId, subscribers);
|
|
421
|
+
}
|
|
422
|
+
notify(options) {
|
|
423
|
+
// Process subscribers asynchronously to avoid blocking workflow execution
|
|
424
|
+
setImmediate(() => this.processSubscriberNotifications(options));
|
|
425
|
+
}
|
|
426
|
+
async processSubscriberNotifications(options) {
|
|
427
|
+
const { workflowId, transactionId, eventType } = options;
|
|
428
|
+
const subscribers = WorkflowOrchestratorService.subscribers.get(workflowId) ?? new Map();
|
|
429
|
+
const notifySubscribersAsync = async (handlers) => {
|
|
430
|
+
const promises = handlers.map(async (handler) => {
|
|
431
|
+
try {
|
|
432
|
+
const result = handler(options);
|
|
433
|
+
if (result && typeof result === "object" && "then" in result) {
|
|
434
|
+
await result;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
catch (error) {
|
|
438
|
+
__classPrivateFieldGet(this, _WorkflowOrchestratorService_logger, "f").error(`Subscriber error: ${error}`);
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
await (0, utils_1.promiseAll)(promises);
|
|
442
|
+
};
|
|
443
|
+
const tasks = [];
|
|
444
|
+
if (transactionId) {
|
|
445
|
+
const transactionSubscribers = subscribers.get(transactionId) ?? [];
|
|
446
|
+
if (transactionSubscribers.length > 0) {
|
|
447
|
+
tasks.push(notifySubscribersAsync(transactionSubscribers));
|
|
448
|
+
}
|
|
449
|
+
if (eventType === "onFinish") {
|
|
450
|
+
subscribers.delete(transactionId);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
const workflowSubscribers = subscribers.get(AnySubscriber) ?? [];
|
|
454
|
+
if (workflowSubscribers.length > 0) {
|
|
455
|
+
tasks.push(notifySubscribersAsync(workflowSubscribers));
|
|
456
|
+
}
|
|
457
|
+
await (0, utils_1.promiseAll)(tasks);
|
|
458
|
+
}
|
|
459
|
+
buildWorkflowEvents({ customEventHandlers, workflowId, transactionId, }) {
|
|
460
|
+
const notify = ({ eventType, step, result, response, errors, state, }) => {
|
|
461
|
+
this.notify({
|
|
462
|
+
workflowId,
|
|
463
|
+
transactionId,
|
|
464
|
+
eventType,
|
|
465
|
+
response,
|
|
466
|
+
step,
|
|
467
|
+
result,
|
|
468
|
+
errors,
|
|
469
|
+
state,
|
|
470
|
+
});
|
|
471
|
+
};
|
|
472
|
+
return {
|
|
473
|
+
onTimeout: ({ transaction }) => {
|
|
474
|
+
customEventHandlers?.onTimeout?.({ transaction });
|
|
475
|
+
notify({ eventType: "onTimeout" });
|
|
476
|
+
},
|
|
477
|
+
onBegin: ({ transaction }) => {
|
|
478
|
+
customEventHandlers?.onBegin?.({ transaction });
|
|
479
|
+
notify({ eventType: "onBegin" });
|
|
480
|
+
},
|
|
481
|
+
onResume: ({ transaction }) => {
|
|
482
|
+
customEventHandlers?.onResume?.({ transaction });
|
|
483
|
+
notify({ eventType: "onResume" });
|
|
484
|
+
},
|
|
485
|
+
onCompensateBegin: ({ transaction }) => {
|
|
486
|
+
customEventHandlers?.onCompensateBegin?.({ transaction });
|
|
487
|
+
notify({ eventType: "onCompensateBegin" });
|
|
488
|
+
},
|
|
489
|
+
onFinish: ({ transaction, result, errors }) => {
|
|
490
|
+
customEventHandlers?.onFinish?.({ transaction, result, errors });
|
|
491
|
+
},
|
|
492
|
+
onStepBegin: ({ step, transaction }) => {
|
|
493
|
+
customEventHandlers?.onStepBegin?.({ step, transaction });
|
|
494
|
+
notify({ eventType: "onStepBegin", step });
|
|
495
|
+
},
|
|
496
|
+
onStepSuccess: async ({ step, transaction }) => {
|
|
497
|
+
const stepName = step.definition.action;
|
|
498
|
+
const response = await (0, workflows_sdk_1.resolveValue)(transaction.getContext().invoke[stepName], transaction);
|
|
499
|
+
customEventHandlers?.onStepSuccess?.({ step, transaction, response });
|
|
500
|
+
notify({ eventType: "onStepSuccess", step, response });
|
|
501
|
+
},
|
|
502
|
+
onStepFailure: ({ step, transaction }) => {
|
|
503
|
+
const stepName = step.definition.action;
|
|
504
|
+
const errors = transaction
|
|
505
|
+
.getErrors(orchestration_1.TransactionHandlerType.INVOKE)
|
|
506
|
+
.filter((err) => err.action === stepName);
|
|
507
|
+
customEventHandlers?.onStepFailure?.({ step, transaction, errors });
|
|
508
|
+
notify({ eventType: "onStepFailure", step, errors });
|
|
509
|
+
},
|
|
510
|
+
onStepAwaiting: ({ step, transaction }) => {
|
|
511
|
+
customEventHandlers?.onStepAwaiting?.({ step, transaction });
|
|
512
|
+
notify({ eventType: "onStepAwaiting", step });
|
|
513
|
+
},
|
|
514
|
+
onCompensateStepSuccess: ({ step, transaction }) => {
|
|
515
|
+
const stepName = step.definition.action;
|
|
516
|
+
const response = transaction.getContext().compensate[stepName];
|
|
517
|
+
customEventHandlers?.onCompensateStepSuccess?.({
|
|
518
|
+
step,
|
|
519
|
+
transaction,
|
|
520
|
+
response,
|
|
521
|
+
});
|
|
522
|
+
notify({ eventType: "onCompensateStepSuccess", step, response });
|
|
523
|
+
},
|
|
524
|
+
onCompensateStepFailure: ({ step, transaction }) => {
|
|
525
|
+
const stepName = step.definition.action;
|
|
526
|
+
const errors = transaction
|
|
527
|
+
.getErrors(orchestration_1.TransactionHandlerType.COMPENSATE)
|
|
528
|
+
.filter((err) => err.action === stepName);
|
|
529
|
+
customEventHandlers?.onStepFailure?.({ step, transaction, errors });
|
|
530
|
+
notify({ eventType: "onCompensateStepFailure", step, errors });
|
|
531
|
+
},
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
buildIdempotencyKeyAndParts(idempotencyKey) {
|
|
535
|
+
const parts = {
|
|
536
|
+
workflowId: "",
|
|
537
|
+
transactionId: "",
|
|
538
|
+
stepId: "",
|
|
539
|
+
action: "invoke",
|
|
540
|
+
};
|
|
541
|
+
let idempotencyKey_ = idempotencyKey;
|
|
542
|
+
const setParts = (workflowId, transactionId, stepId, action) => {
|
|
543
|
+
parts.workflowId = workflowId;
|
|
544
|
+
parts.transactionId = transactionId;
|
|
545
|
+
parts.stepId = stepId;
|
|
546
|
+
parts.action = action;
|
|
547
|
+
};
|
|
548
|
+
if (!(0, utils_1.isString)(idempotencyKey)) {
|
|
549
|
+
const { workflowId, transactionId, stepId, action } = idempotencyKey;
|
|
550
|
+
idempotencyKey_ = [workflowId, transactionId, stepId, action].join(":");
|
|
551
|
+
setParts(workflowId, transactionId, stepId, action);
|
|
552
|
+
}
|
|
553
|
+
else {
|
|
554
|
+
const [workflowId, transactionId, stepId, action] = idempotencyKey_.split(":");
|
|
555
|
+
setParts(workflowId, transactionId, stepId, action);
|
|
556
|
+
}
|
|
557
|
+
return [idempotencyKey_, parts];
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
exports.WorkflowOrchestratorService = WorkflowOrchestratorService;
|
|
561
|
+
_WorkflowOrchestratorService_logger = new WeakMap();
|
|
562
|
+
WorkflowOrchestratorService.subscribers = new Map();
|
|
563
|
+
//# sourceMappingURL=workflow-orchestrator.js.map
|