@8medusa/orchestration 2.7.0
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/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/joiner/helpers.d.ts +3 -0
- package/dist/joiner/helpers.d.ts.map +1 -0
- package/dist/joiner/helpers.js +69 -0
- package/dist/joiner/helpers.js.map +1 -0
- package/dist/joiner/index.d.ts +3 -0
- package/dist/joiner/index.d.ts.map +1 -0
- package/dist/joiner/index.js +19 -0
- package/dist/joiner/index.js.map +1 -0
- package/dist/joiner/remote-joiner.d.ts +42 -0
- package/dist/joiner/remote-joiner.d.ts.map +1 -0
- package/dist/joiner/remote-joiner.js +1108 -0
- package/dist/joiner/remote-joiner.js.map +1 -0
- package/dist/transaction/datastore/abstract-storage.d.ts +42 -0
- package/dist/transaction/datastore/abstract-storage.d.ts.map +1 -0
- package/dist/transaction/datastore/abstract-storage.js +52 -0
- package/dist/transaction/datastore/abstract-storage.js.map +1 -0
- package/dist/transaction/datastore/base-in-memory-storage.d.ts +11 -0
- package/dist/transaction/datastore/base-in-memory-storage.d.ts.map +1 -0
- package/dist/transaction/datastore/base-in-memory-storage.js +33 -0
- package/dist/transaction/datastore/base-in-memory-storage.js.map +1 -0
- package/dist/transaction/distributed-transaction.d.ts +99 -0
- package/dist/transaction/distributed-transaction.d.ts.map +1 -0
- package/dist/transaction/distributed-transaction.js +258 -0
- package/dist/transaction/distributed-transaction.js.map +1 -0
- package/dist/transaction/errors.d.ts +31 -0
- package/dist/transaction/errors.d.ts.map +1 -0
- package/dist/transaction/errors.js +89 -0
- package/dist/transaction/errors.js.map +1 -0
- package/dist/transaction/index.d.ts +8 -0
- package/dist/transaction/index.d.ts.map +1 -0
- package/dist/transaction/index.js +24 -0
- package/dist/transaction/index.js.map +1 -0
- package/dist/transaction/orchestrator-builder.d.ts +36 -0
- package/dist/transaction/orchestrator-builder.d.ts.map +1 -0
- package/dist/transaction/orchestrator-builder.js +300 -0
- package/dist/transaction/orchestrator-builder.js.map +1 -0
- package/dist/transaction/transaction-orchestrator.d.ts +181 -0
- package/dist/transaction/transaction-orchestrator.d.ts.map +1 -0
- package/dist/transaction/transaction-orchestrator.js +1061 -0
- package/dist/transaction/transaction-orchestrator.js.map +1 -0
- package/dist/transaction/transaction-step.d.ts +67 -0
- package/dist/transaction/transaction-step.d.ts.map +1 -0
- package/dist/transaction/transaction-step.js +146 -0
- package/dist/transaction/transaction-step.js.map +1 -0
- package/dist/transaction/types.d.ts +236 -0
- package/dist/transaction/types.d.ts.map +1 -0
- package/dist/transaction/types.js +23 -0
- package/dist/transaction/types.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/workflow/global-workflow.d.ts +14 -0
- package/dist/workflow/global-workflow.d.ts.map +1 -0
- package/dist/workflow/global-workflow.js +105 -0
- package/dist/workflow/global-workflow.js.map +1 -0
- package/dist/workflow/index.d.ts +5 -0
- package/dist/workflow/index.d.ts.map +1 -0
- package/dist/workflow/index.js +21 -0
- package/dist/workflow/index.js.map +1 -0
- package/dist/workflow/local-workflow.d.ts +46 -0
- package/dist/workflow/local-workflow.d.ts.map +1 -0
- package/dist/workflow/local-workflow.js +360 -0
- package/dist/workflow/local-workflow.js.map +1 -0
- package/dist/workflow/scheduler.d.ts +12 -0
- package/dist/workflow/scheduler.d.ts.map +1 -0
- package/dist/workflow/scheduler.js +35 -0
- package/dist/workflow/scheduler.js.map +1 -0
- package/dist/workflow/workflow-manager.d.ts +38 -0
- package/dist/workflow/workflow-manager.d.ts.map +1 -0
- package/dist/workflow/workflow-manager.js +124 -0
- package/dist/workflow/workflow-manager.js.map +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GlobalWorkflow = void 0;
|
|
4
|
+
const utils_1 = require("@8medusa/utils");
|
|
5
|
+
const awilix_1 = require("awilix");
|
|
6
|
+
const workflow_manager_1 = require("./workflow-manager");
|
|
7
|
+
class GlobalWorkflow extends workflow_manager_1.WorkflowManager {
|
|
8
|
+
constructor(modulesLoaded, context, subscribe) {
|
|
9
|
+
super();
|
|
10
|
+
let container;
|
|
11
|
+
if (!Array.isArray(modulesLoaded) && modulesLoaded) {
|
|
12
|
+
if (!("cradle" in modulesLoaded)) {
|
|
13
|
+
container = (0, utils_1.createMedusaContainer)(modulesLoaded);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
container = modulesLoaded;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
else if (Array.isArray(modulesLoaded) && modulesLoaded.length) {
|
|
20
|
+
container = (0, utils_1.createMedusaContainer)();
|
|
21
|
+
for (const mod of modulesLoaded || []) {
|
|
22
|
+
const keyName = mod.__definition.key;
|
|
23
|
+
container.register(keyName, (0, awilix_1.asValue)(mod));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
this.container = container;
|
|
27
|
+
this.context = context ?? {};
|
|
28
|
+
this.subscribe = subscribe ?? {};
|
|
29
|
+
}
|
|
30
|
+
async run(workflowId, uniqueTransactionId, input) {
|
|
31
|
+
if (!workflow_manager_1.WorkflowManager.workflows.has(workflowId)) {
|
|
32
|
+
throw new Error(`Workflow with id "${workflowId}" not found.`);
|
|
33
|
+
}
|
|
34
|
+
const workflow = workflow_manager_1.WorkflowManager.workflows.get(workflowId);
|
|
35
|
+
const orchestrator = workflow.orchestrator;
|
|
36
|
+
const transaction = await orchestrator.beginTransaction({
|
|
37
|
+
transactionId: uniqueTransactionId,
|
|
38
|
+
handler: workflow.handler(this.container, this.context),
|
|
39
|
+
payload: input,
|
|
40
|
+
});
|
|
41
|
+
if (this.subscribe.onStepBegin) {
|
|
42
|
+
transaction.once("stepBegin", this.subscribe.onStepBegin);
|
|
43
|
+
}
|
|
44
|
+
if (this.subscribe.onStepSuccess) {
|
|
45
|
+
transaction.once("stepSuccess", this.subscribe.onStepSuccess);
|
|
46
|
+
}
|
|
47
|
+
if (this.subscribe.onStepFailure) {
|
|
48
|
+
transaction.once("stepFailure", this.subscribe.onStepFailure);
|
|
49
|
+
}
|
|
50
|
+
if (this.subscribe.onStepAwaiting) {
|
|
51
|
+
transaction.once("stepAwaiting", this.subscribe.onStepAwaiting);
|
|
52
|
+
}
|
|
53
|
+
await orchestrator.resume(transaction);
|
|
54
|
+
return transaction;
|
|
55
|
+
}
|
|
56
|
+
async registerStepSuccess(workflowId, idempotencyKey, response) {
|
|
57
|
+
if (!workflow_manager_1.WorkflowManager.workflows.has(workflowId)) {
|
|
58
|
+
throw new Error(`Workflow with id "${workflowId}" not found.`);
|
|
59
|
+
}
|
|
60
|
+
const workflow = workflow_manager_1.WorkflowManager.workflows.get(workflowId);
|
|
61
|
+
const orchestrator = workflow.orchestrator;
|
|
62
|
+
orchestrator.once("resume", (transaction) => {
|
|
63
|
+
if (this.subscribe.onStepBegin) {
|
|
64
|
+
transaction.once("stepBegin", this.subscribe.onStepBegin);
|
|
65
|
+
}
|
|
66
|
+
if (this.subscribe.onStepSuccess) {
|
|
67
|
+
transaction.once("stepSuccess", this.subscribe.onStepSuccess);
|
|
68
|
+
}
|
|
69
|
+
if (this.subscribe.onStepFailure) {
|
|
70
|
+
transaction.once("stepFailure", this.subscribe.onStepFailure);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return await workflow.orchestrator.registerStepSuccess({
|
|
74
|
+
responseIdempotencyKey: idempotencyKey,
|
|
75
|
+
handler: workflow.handler(this.container, this.context),
|
|
76
|
+
response,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
async registerStepFailure(workflowId, idempotencyKey, error) {
|
|
80
|
+
if (!workflow_manager_1.WorkflowManager.workflows.has(workflowId)) {
|
|
81
|
+
throw new Error(`Workflow with id "${workflowId}" not found.`);
|
|
82
|
+
}
|
|
83
|
+
const workflow = workflow_manager_1.WorkflowManager.workflows.get(workflowId);
|
|
84
|
+
const orchestrator = workflow.orchestrator;
|
|
85
|
+
orchestrator.once("resume", (transaction) => {
|
|
86
|
+
if (this.subscribe.onStepBegin) {
|
|
87
|
+
transaction.once("stepBegin", this.subscribe.onStepBegin);
|
|
88
|
+
}
|
|
89
|
+
if (this.subscribe.onStepSuccess) {
|
|
90
|
+
transaction.once("stepSuccess", this.subscribe.onStepSuccess);
|
|
91
|
+
}
|
|
92
|
+
if (this.subscribe.onStepFailure) {
|
|
93
|
+
transaction.once("stepFailure", this.subscribe.onStepFailure);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return await workflow.orchestrator.registerStepFailure({
|
|
97
|
+
responseIdempotencyKey: idempotencyKey,
|
|
98
|
+
error,
|
|
99
|
+
handler: workflow.handler(this.container, this.context),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.GlobalWorkflow = GlobalWorkflow;
|
|
104
|
+
GlobalWorkflow.workflows = new Map();
|
|
105
|
+
//# sourceMappingURL=global-workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-workflow.js","sourceRoot":"","sources":["../../src/workflow/global-workflow.ts"],"names":[],"mappings":";;;AACA,0CAAsD;AACtD,mCAAgC;AAMhC,yDAAwE;AAExE,MAAa,cAAe,SAAQ,kCAAe;IAMjD,YACE,aAAgD,EAChD,OAAiB,EACjB,SAAwC;QAExC,KAAK,EAAE,CAAA;QAEP,IAAI,SAAS,CAAA;QAEb,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,aAAa,EAAE,CAAC;YACnD,IAAI,CAAC,CAAC,QAAQ,IAAI,aAAa,CAAC,EAAE,CAAC;gBACjC,SAAS,GAAG,IAAA,6BAAqB,EAAC,aAAa,CAAC,CAAA;YAClD,CAAC;iBAAM,CAAC;gBACN,SAAS,GAAG,aAAa,CAAA;YAC3B,CAAC;QACH,CAAC;aAA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,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAA;YAC/D,CAAC;QACH,CAAC,CAAC,CAAA;QAEF,OAAO,MAAM,QAAQ,CAAC,YAAY,CAAC,mBAAmB,CAAC;YACrD,sBAAsB,EAAE,cAAc;YACtC,KAAK;YACL,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC;SACxD,CAAC,CAAA;IACJ,CAAC;;AArIH,wCAsIC;AArIkB,wBAAS,GAAoC,IAAI,GAAG,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/workflow/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./workflow-manager"), exports);
|
|
18
|
+
__exportStar(require("./local-workflow"), exports);
|
|
19
|
+
__exportStar(require("./global-workflow"), exports);
|
|
20
|
+
__exportStar(require("./scheduler"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/workflow/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAkC;AAClC,mDAAgC;AAChC,oDAAiC;AACjC,8CAA2B"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Context, LoadedModule, MedusaContainer } from "@8medusa/types";
|
|
2
|
+
import { DistributedTransactionEvents, DistributedTransactionType, TransactionFlow, TransactionModelOptions, TransactionStepsDefinition } from "../transaction";
|
|
3
|
+
import { OrchestratorBuilder } from "../transaction/orchestrator-builder";
|
|
4
|
+
import { WorkflowDefinition, WorkflowStepHandler } from "./workflow-manager";
|
|
5
|
+
type StepHandler = {
|
|
6
|
+
invoke: WorkflowStepHandler;
|
|
7
|
+
compensate?: WorkflowStepHandler;
|
|
8
|
+
};
|
|
9
|
+
export declare class LocalWorkflow {
|
|
10
|
+
protected container_: MedusaContainer;
|
|
11
|
+
protected workflowId: string;
|
|
12
|
+
protected flow: OrchestratorBuilder;
|
|
13
|
+
protected customOptions: Partial<TransactionModelOptions>;
|
|
14
|
+
protected workflow: WorkflowDefinition;
|
|
15
|
+
protected handlers: Map<string, StepHandler>;
|
|
16
|
+
protected medusaContext?: Context;
|
|
17
|
+
get container(): MedusaContainer;
|
|
18
|
+
set container(modulesLoaded: LoadedModule[] | MedusaContainer);
|
|
19
|
+
constructor(workflowId: string, modulesLoaded?: LoadedModule[] | MedusaContainer);
|
|
20
|
+
private resolveContainer;
|
|
21
|
+
private contextualizedMedusaModules;
|
|
22
|
+
protected commit(): void;
|
|
23
|
+
getFlow(): TransactionStepsDefinition;
|
|
24
|
+
private registerEventCallbacks;
|
|
25
|
+
run(uniqueTransactionId: string, input?: unknown, context?: Context, subscribe?: DistributedTransactionEvents, flowMetadata?: TransactionFlow["metadata"]): Promise<DistributedTransactionType>;
|
|
26
|
+
getRunningTransaction(uniqueTransactionId: string, context?: Context): Promise<DistributedTransactionType>;
|
|
27
|
+
cancel(transactionOrTransactionId: string | DistributedTransactionType, _?: unknown, // not used but a common argument on other methods called dynamically
|
|
28
|
+
context?: Context, subscribe?: DistributedTransactionEvents): Promise<DistributedTransactionType>;
|
|
29
|
+
registerStepSuccess(idempotencyKey: string, response?: unknown, context?: Context, subscribe?: DistributedTransactionEvents): Promise<DistributedTransactionType>;
|
|
30
|
+
registerStepFailure(idempotencyKey: string, error?: Error | any, context?: Context, subscribe?: DistributedTransactionEvents): Promise<DistributedTransactionType>;
|
|
31
|
+
setOptions(options: Partial<TransactionModelOptions>): this;
|
|
32
|
+
addAction(action: string, handler: StepHandler, options?: Partial<TransactionStepsDefinition>): OrchestratorBuilder;
|
|
33
|
+
replaceAction(existingAction: string, action: string, handler: StepHandler, options?: Partial<TransactionStepsDefinition>): OrchestratorBuilder;
|
|
34
|
+
insertActionBefore(existingAction: string, action: string, handler: StepHandler, options?: Partial<TransactionStepsDefinition>): OrchestratorBuilder;
|
|
35
|
+
insertActionAfter(existingAction: string, action: string, handler: StepHandler, options?: Partial<TransactionStepsDefinition>): OrchestratorBuilder;
|
|
36
|
+
appendAction(action: string, to: string, handler: StepHandler, options?: Partial<TransactionStepsDefinition>): OrchestratorBuilder;
|
|
37
|
+
moveAction(actionToMove: string, targetAction: string): OrchestratorBuilder;
|
|
38
|
+
moveAndMergeNextAction(actionToMove: string, targetAction: string): OrchestratorBuilder;
|
|
39
|
+
mergeActions(where: string, ...actions: string[]): OrchestratorBuilder;
|
|
40
|
+
deleteAction(action: string, parentSteps?: any): OrchestratorBuilder;
|
|
41
|
+
pruneAction(action: string): OrchestratorBuilder;
|
|
42
|
+
protected assertHandler(handler: StepHandler, action: string): void | never;
|
|
43
|
+
private onLoad;
|
|
44
|
+
}
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=local-workflow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-workflow.d.ts","sourceRoot":"","sources":["../../src/workflow/local-workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAWvE,OAAO,EAEL,4BAA4B,EAC5B,0BAA0B,EAC1B,eAAe,EACf,uBAAuB,EAEvB,0BAA0B,EAC3B,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;AACzE,OAAO,EACL,kBAAkB,EAElB,mBAAmB,EACpB,MAAM,oBAAoB,CAAA;AAE3B,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,mBAAmB,CAAA;IAC3B,UAAU,CAAC,EAAE,mBAAmB,CAAA;CACjC,CAAA;AAED,qBAAa,aAAa;IACxB,SAAS,CAAC,UAAU,EAAE,eAAe,CAAA;IACrC,SAAS,CAAC,UAAU,EAAE,MAAM,CAAA;IAC5B,SAAS,CAAC,IAAI,EAAE,mBAAmB,CAAA;IACnC,SAAS,CAAC,aAAa,EAAE,OAAO,CAAC,uBAAuB,CAAC,CAAK;IAC9D,SAAS,CAAC,QAAQ,EAAE,kBAAkB,CAAA;IACtC,SAAS,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;IAC5C,SAAS,CAAC,aAAa,CAAC,EAAE,OAAO,CAAA;IAEjC,IAAI,SAAS,IAAI,eAAe,CAE/B;IAED,IAAI,SAAS,CAAC,aAAa,EAAE,YAAY,EAAE,GAAG,eAAe,EAE5D;gBAGC,UAAU,EAAE,MAAM,EAClB,aAAa,CAAC,EAAE,YAAY,EAAE,GAAG,eAAe;IAuBlD,OAAO,CAAC,gBAAgB;IAqBxB,OAAO,CAAC,2BAA2B;IA4CnC,SAAS,CAAC,MAA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BAAiB,CACf,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,WAAW,EACpB,OAAO,GAAE,OAAO,CAAC,0BAA0B,CAAM;IAQnD,YAAY,CACV,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,WAAW,EACpB,OAAO,GAAE,OAAO,CAAC,0BAA0B,CAAM;IAQnD,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,mBAAmB;IAI3E,sBAAsB,CACpB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,GACnB,mBAAmB;IAItB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE;IAIhD,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,KAAA;IAIzC,WAAW,CAAC,MAAM,EAAE,MAAM;IAI1B,SAAS,CAAC,aAAa,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,KAAK;IAQ3E,OAAO,CAAC,MAAM;CAWf"}
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LocalWorkflow = void 0;
|
|
4
|
+
const utils_1 = require("@8medusa/utils");
|
|
5
|
+
const awilix_1 = require("awilix");
|
|
6
|
+
const transaction_1 = require("../transaction");
|
|
7
|
+
const orchestrator_builder_1 = require("../transaction/orchestrator-builder");
|
|
8
|
+
const workflow_manager_1 = require("./workflow-manager");
|
|
9
|
+
class LocalWorkflow {
|
|
10
|
+
get container() {
|
|
11
|
+
return this.container_;
|
|
12
|
+
}
|
|
13
|
+
set container(modulesLoaded) {
|
|
14
|
+
this.resolveContainer(modulesLoaded);
|
|
15
|
+
}
|
|
16
|
+
constructor(workflowId, modulesLoaded) {
|
|
17
|
+
this.customOptions = {};
|
|
18
|
+
const globalWorkflow = workflow_manager_1.WorkflowManager.getWorkflow(workflowId);
|
|
19
|
+
if (!globalWorkflow) {
|
|
20
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.NOT_FOUND, `Workflow with id "${workflowId}" not found.`);
|
|
21
|
+
}
|
|
22
|
+
const workflow = {
|
|
23
|
+
...globalWorkflow,
|
|
24
|
+
orchestrator: transaction_1.TransactionOrchestrator.clone(globalWorkflow.orchestrator),
|
|
25
|
+
};
|
|
26
|
+
this.flow = new orchestrator_builder_1.OrchestratorBuilder(workflow.flow_);
|
|
27
|
+
this.workflowId = workflowId;
|
|
28
|
+
this.workflow = workflow;
|
|
29
|
+
this.handlers = new Map(workflow.handlers_);
|
|
30
|
+
this.resolveContainer(modulesLoaded);
|
|
31
|
+
}
|
|
32
|
+
resolveContainer(modulesLoaded) {
|
|
33
|
+
let container;
|
|
34
|
+
if (!Array.isArray(modulesLoaded) && modulesLoaded) {
|
|
35
|
+
if (!("cradle" in modulesLoaded)) {
|
|
36
|
+
container = (0, utils_1.createMedusaContainer)(modulesLoaded);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
container = (0, utils_1.createMedusaContainer)({}, modulesLoaded); // copy container
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (Array.isArray(modulesLoaded) && modulesLoaded.length) {
|
|
43
|
+
container = (0, utils_1.createMedusaContainer)();
|
|
44
|
+
for (const mod of modulesLoaded || []) {
|
|
45
|
+
const keyName = mod.__definition.key;
|
|
46
|
+
container.register(keyName, (0, awilix_1.asValue)(mod));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
this.container_ = this.contextualizedMedusaModules(container);
|
|
50
|
+
}
|
|
51
|
+
contextualizedMedusaModules(container) {
|
|
52
|
+
if (!container) {
|
|
53
|
+
return (0, utils_1.createMedusaContainer)();
|
|
54
|
+
}
|
|
55
|
+
// eslint-disable-next-line
|
|
56
|
+
const this_ = this;
|
|
57
|
+
const originalResolver = container.resolve;
|
|
58
|
+
container.resolve = function (keyName, opts) {
|
|
59
|
+
const resolved = originalResolver(keyName, opts);
|
|
60
|
+
if (resolved?.constructor?.__type !== utils_1.MedusaModuleType) {
|
|
61
|
+
return resolved;
|
|
62
|
+
}
|
|
63
|
+
return new Proxy(resolved, {
|
|
64
|
+
get: function (target, prop) {
|
|
65
|
+
if (typeof target[prop] !== "function") {
|
|
66
|
+
return target[prop];
|
|
67
|
+
}
|
|
68
|
+
return (...args) => {
|
|
69
|
+
const ctxIndex = utils_1.MedusaContext.getIndex(target, prop);
|
|
70
|
+
const hasContext = args[ctxIndex]?.__type === utils_1.MedusaContextType;
|
|
71
|
+
if (!hasContext && (0, utils_1.isDefined)(ctxIndex)) {
|
|
72
|
+
const context = this_.medusaContext;
|
|
73
|
+
if (context?.__type === utils_1.MedusaContextType) {
|
|
74
|
+
delete context?.manager;
|
|
75
|
+
delete context?.transactionManager;
|
|
76
|
+
args[ctxIndex] = context;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const method = target[prop];
|
|
80
|
+
return method.apply(target, [...args]);
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
return container;
|
|
86
|
+
}
|
|
87
|
+
commit() {
|
|
88
|
+
const finalFlow = this.flow.build();
|
|
89
|
+
const globalWorkflow = workflow_manager_1.WorkflowManager.getWorkflow(this.workflowId);
|
|
90
|
+
const customOptions = {
|
|
91
|
+
...globalWorkflow?.options,
|
|
92
|
+
...this.customOptions,
|
|
93
|
+
};
|
|
94
|
+
this.workflow = {
|
|
95
|
+
id: this.workflowId,
|
|
96
|
+
flow_: finalFlow,
|
|
97
|
+
orchestrator: new transaction_1.TransactionOrchestrator({
|
|
98
|
+
id: this.workflowId,
|
|
99
|
+
definition: finalFlow,
|
|
100
|
+
options: customOptions,
|
|
101
|
+
}),
|
|
102
|
+
options: customOptions,
|
|
103
|
+
handler: workflow_manager_1.WorkflowManager.buildHandlers(this.handlers),
|
|
104
|
+
handlers_: this.handlers,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
getFlow() {
|
|
108
|
+
if (this.flow.hasChanges) {
|
|
109
|
+
this.commit();
|
|
110
|
+
}
|
|
111
|
+
return this.workflow.flow_;
|
|
112
|
+
}
|
|
113
|
+
registerEventCallbacks({ orchestrator, transaction, subscribe, idempotencyKey, }) {
|
|
114
|
+
const modelId = orchestrator.id;
|
|
115
|
+
let transactionId;
|
|
116
|
+
if (transaction) {
|
|
117
|
+
transactionId = transaction.transactionId;
|
|
118
|
+
}
|
|
119
|
+
else if (idempotencyKey) {
|
|
120
|
+
const [, trxId] = idempotencyKey.split(":");
|
|
121
|
+
transactionId = trxId;
|
|
122
|
+
}
|
|
123
|
+
const eventWrapperMap = new Map();
|
|
124
|
+
for (const [key, handler] of Object.entries(subscribe ?? {})) {
|
|
125
|
+
eventWrapperMap.set(key, (args) => {
|
|
126
|
+
const { transaction } = args;
|
|
127
|
+
if (transaction.transactionId !== transactionId ||
|
|
128
|
+
transaction.modelId !== modelId) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
handler(args);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
if (subscribe?.onBegin) {
|
|
135
|
+
orchestrator.on(transaction_1.DistributedTransactionEvent.BEGIN, eventWrapperMap.get("onBegin"));
|
|
136
|
+
}
|
|
137
|
+
if (subscribe?.onResume) {
|
|
138
|
+
orchestrator.on(transaction_1.DistributedTransactionEvent.RESUME, eventWrapperMap.get("onResume"));
|
|
139
|
+
}
|
|
140
|
+
if (subscribe?.onCompensateBegin) {
|
|
141
|
+
orchestrator.on(transaction_1.DistributedTransactionEvent.COMPENSATE_BEGIN, eventWrapperMap.get("onCompensateBegin"));
|
|
142
|
+
}
|
|
143
|
+
if (subscribe?.onTimeout) {
|
|
144
|
+
orchestrator.on(transaction_1.DistributedTransactionEvent.TIMEOUT, eventWrapperMap.get("onTimeout"));
|
|
145
|
+
}
|
|
146
|
+
if (subscribe?.onFinish) {
|
|
147
|
+
orchestrator.on(transaction_1.DistributedTransactionEvent.FINISH, eventWrapperMap.get("onFinish"));
|
|
148
|
+
}
|
|
149
|
+
const resumeWrapper = ({ transaction }) => {
|
|
150
|
+
if (transaction.modelId !== modelId ||
|
|
151
|
+
transaction.transactionId !== transactionId) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (subscribe?.onStepBegin) {
|
|
155
|
+
transaction.on(transaction_1.DistributedTransactionEvent.STEP_BEGIN, eventWrapperMap.get("onStepBegin"));
|
|
156
|
+
}
|
|
157
|
+
if (subscribe?.onStepSuccess) {
|
|
158
|
+
transaction.on(transaction_1.DistributedTransactionEvent.STEP_SUCCESS, eventWrapperMap.get("onStepSuccess"));
|
|
159
|
+
}
|
|
160
|
+
if (subscribe?.onStepFailure) {
|
|
161
|
+
transaction.on(transaction_1.DistributedTransactionEvent.STEP_FAILURE, eventWrapperMap.get("onStepFailure"));
|
|
162
|
+
}
|
|
163
|
+
if (subscribe?.onStepAwaiting) {
|
|
164
|
+
transaction.on(transaction_1.DistributedTransactionEvent.STEP_AWAITING, eventWrapperMap.get("onStepAwaiting"));
|
|
165
|
+
}
|
|
166
|
+
if (subscribe?.onCompensateStepSuccess) {
|
|
167
|
+
transaction.on(transaction_1.DistributedTransactionEvent.COMPENSATE_STEP_SUCCESS, eventWrapperMap.get("onCompensateStepSuccess"));
|
|
168
|
+
}
|
|
169
|
+
if (subscribe?.onCompensateStepFailure) {
|
|
170
|
+
transaction.on(transaction_1.DistributedTransactionEvent.COMPENSATE_STEP_FAILURE, eventWrapperMap.get("onCompensateStepFailure"));
|
|
171
|
+
}
|
|
172
|
+
if (subscribe?.onStepSkipped) {
|
|
173
|
+
transaction.on(transaction_1.DistributedTransactionEvent.STEP_SKIPPED, eventWrapperMap.get("onStepSkipped"));
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
if (transaction) {
|
|
177
|
+
resumeWrapper({ transaction });
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
orchestrator.once("resume", resumeWrapper);
|
|
181
|
+
}
|
|
182
|
+
const cleanUp = () => {
|
|
183
|
+
subscribe?.onFinish &&
|
|
184
|
+
orchestrator.removeListener(transaction_1.DistributedTransactionEvent.FINISH, eventWrapperMap.get("onFinish"));
|
|
185
|
+
subscribe?.onResume &&
|
|
186
|
+
orchestrator.removeListener(transaction_1.DistributedTransactionEvent.RESUME, eventWrapperMap.get("onResume"));
|
|
187
|
+
subscribe?.onBegin &&
|
|
188
|
+
orchestrator.removeListener(transaction_1.DistributedTransactionEvent.BEGIN, eventWrapperMap.get("onBegin"));
|
|
189
|
+
subscribe?.onCompensateBegin &&
|
|
190
|
+
orchestrator.removeListener(transaction_1.DistributedTransactionEvent.COMPENSATE_BEGIN, eventWrapperMap.get("onCompensateBegin"));
|
|
191
|
+
subscribe?.onTimeout &&
|
|
192
|
+
orchestrator.removeListener(transaction_1.DistributedTransactionEvent.TIMEOUT, eventWrapperMap.get("onTimeout"));
|
|
193
|
+
orchestrator.removeListener(transaction_1.DistributedTransactionEvent.RESUME, resumeWrapper);
|
|
194
|
+
eventWrapperMap.clear();
|
|
195
|
+
};
|
|
196
|
+
return {
|
|
197
|
+
cleanUpEventListeners: cleanUp,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
async run(uniqueTransactionId, input, context, subscribe, flowMetadata) {
|
|
201
|
+
if (this.flow.hasChanges) {
|
|
202
|
+
this.commit();
|
|
203
|
+
}
|
|
204
|
+
this.medusaContext = context;
|
|
205
|
+
const { handler, orchestrator } = this.workflow;
|
|
206
|
+
const transaction = await orchestrator.beginTransaction({
|
|
207
|
+
transactionId: uniqueTransactionId,
|
|
208
|
+
handler: handler(this.container_, context),
|
|
209
|
+
payload: input,
|
|
210
|
+
flowMetadata,
|
|
211
|
+
onLoad: this.onLoad.bind(this),
|
|
212
|
+
});
|
|
213
|
+
const { cleanUpEventListeners } = this.registerEventCallbacks({
|
|
214
|
+
orchestrator,
|
|
215
|
+
transaction,
|
|
216
|
+
subscribe,
|
|
217
|
+
});
|
|
218
|
+
await orchestrator.resume(transaction);
|
|
219
|
+
try {
|
|
220
|
+
return transaction;
|
|
221
|
+
}
|
|
222
|
+
finally {
|
|
223
|
+
cleanUpEventListeners();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
async getRunningTransaction(uniqueTransactionId, context) {
|
|
227
|
+
this.medusaContext = context;
|
|
228
|
+
const { handler, orchestrator } = this.workflow;
|
|
229
|
+
const transaction = await orchestrator.retrieveExistingTransaction(uniqueTransactionId, handler(this.container_, context));
|
|
230
|
+
return transaction;
|
|
231
|
+
}
|
|
232
|
+
async cancel(transactionOrTransactionId, _, // not used but a common argument on other methods called dynamically
|
|
233
|
+
context, subscribe) {
|
|
234
|
+
this.medusaContext = context;
|
|
235
|
+
const { orchestrator } = this.workflow;
|
|
236
|
+
const transaction = (0, utils_1.isString)(transactionOrTransactionId)
|
|
237
|
+
? await this.getRunningTransaction(transactionOrTransactionId, context)
|
|
238
|
+
: transactionOrTransactionId;
|
|
239
|
+
if (this.medusaContext) {
|
|
240
|
+
this.medusaContext.eventGroupId =
|
|
241
|
+
transaction.getFlow().metadata?.eventGroupId;
|
|
242
|
+
}
|
|
243
|
+
const { cleanUpEventListeners } = this.registerEventCallbacks({
|
|
244
|
+
orchestrator,
|
|
245
|
+
transaction,
|
|
246
|
+
subscribe,
|
|
247
|
+
});
|
|
248
|
+
await orchestrator.cancelTransaction(transaction);
|
|
249
|
+
try {
|
|
250
|
+
return transaction;
|
|
251
|
+
}
|
|
252
|
+
finally {
|
|
253
|
+
cleanUpEventListeners();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
async registerStepSuccess(idempotencyKey, response, context, subscribe) {
|
|
257
|
+
this.medusaContext = context;
|
|
258
|
+
const { handler, orchestrator } = this.workflow;
|
|
259
|
+
const { cleanUpEventListeners } = this.registerEventCallbacks({
|
|
260
|
+
orchestrator,
|
|
261
|
+
idempotencyKey,
|
|
262
|
+
subscribe,
|
|
263
|
+
});
|
|
264
|
+
const transaction = await orchestrator.registerStepSuccess({
|
|
265
|
+
responseIdempotencyKey: idempotencyKey,
|
|
266
|
+
handler: handler(this.container_, context),
|
|
267
|
+
response,
|
|
268
|
+
onLoad: this.onLoad.bind(this),
|
|
269
|
+
});
|
|
270
|
+
try {
|
|
271
|
+
return transaction;
|
|
272
|
+
}
|
|
273
|
+
finally {
|
|
274
|
+
cleanUpEventListeners();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
async registerStepFailure(idempotencyKey, error, context, subscribe) {
|
|
278
|
+
this.medusaContext = context;
|
|
279
|
+
const { handler, orchestrator } = this.workflow;
|
|
280
|
+
const { cleanUpEventListeners } = this.registerEventCallbacks({
|
|
281
|
+
orchestrator,
|
|
282
|
+
idempotencyKey,
|
|
283
|
+
subscribe,
|
|
284
|
+
});
|
|
285
|
+
const transaction = await orchestrator.registerStepFailure({
|
|
286
|
+
responseIdempotencyKey: idempotencyKey,
|
|
287
|
+
error,
|
|
288
|
+
handler: handler(this.container_, context),
|
|
289
|
+
onLoad: this.onLoad.bind(this),
|
|
290
|
+
});
|
|
291
|
+
try {
|
|
292
|
+
return transaction;
|
|
293
|
+
}
|
|
294
|
+
finally {
|
|
295
|
+
cleanUpEventListeners();
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
setOptions(options) {
|
|
299
|
+
this.customOptions = options;
|
|
300
|
+
return this;
|
|
301
|
+
}
|
|
302
|
+
addAction(action, handler, options = {}) {
|
|
303
|
+
this.assertHandler(handler, action);
|
|
304
|
+
this.handlers.set(action, handler);
|
|
305
|
+
return this.flow.addAction(action, options);
|
|
306
|
+
}
|
|
307
|
+
replaceAction(existingAction, action, handler, options = {}) {
|
|
308
|
+
this.assertHandler(handler, action);
|
|
309
|
+
this.handlers.set(action, handler);
|
|
310
|
+
return this.flow.replaceAction(existingAction, action, options);
|
|
311
|
+
}
|
|
312
|
+
insertActionBefore(existingAction, action, handler, options = {}) {
|
|
313
|
+
this.assertHandler(handler, action);
|
|
314
|
+
this.handlers.set(action, handler);
|
|
315
|
+
return this.flow.insertActionBefore(existingAction, action, options);
|
|
316
|
+
}
|
|
317
|
+
insertActionAfter(existingAction, action, handler, options = {}) {
|
|
318
|
+
this.assertHandler(handler, action);
|
|
319
|
+
this.handlers.set(action, handler);
|
|
320
|
+
return this.flow.insertActionAfter(existingAction, action, options);
|
|
321
|
+
}
|
|
322
|
+
appendAction(action, to, handler, options = {}) {
|
|
323
|
+
this.assertHandler(handler, action);
|
|
324
|
+
this.handlers.set(action, handler);
|
|
325
|
+
return this.flow.appendAction(action, to, options);
|
|
326
|
+
}
|
|
327
|
+
moveAction(actionToMove, targetAction) {
|
|
328
|
+
return this.flow.moveAction(actionToMove, targetAction);
|
|
329
|
+
}
|
|
330
|
+
moveAndMergeNextAction(actionToMove, targetAction) {
|
|
331
|
+
return this.flow.moveAndMergeNextAction(actionToMove, targetAction);
|
|
332
|
+
}
|
|
333
|
+
mergeActions(where, ...actions) {
|
|
334
|
+
return this.flow.mergeActions(where, ...actions);
|
|
335
|
+
}
|
|
336
|
+
deleteAction(action, parentSteps) {
|
|
337
|
+
return this.flow.deleteAction(action, parentSteps);
|
|
338
|
+
}
|
|
339
|
+
pruneAction(action) {
|
|
340
|
+
return this.flow.pruneAction(action);
|
|
341
|
+
}
|
|
342
|
+
assertHandler(handler, action) {
|
|
343
|
+
if (!handler?.invoke) {
|
|
344
|
+
throw new Error(`Handler for action "${action}" is missing invoke function.`);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
onLoad(transaction) {
|
|
348
|
+
if (this.medusaContext) {
|
|
349
|
+
const flow = transaction.getFlow() ?? {};
|
|
350
|
+
const metadata = (flow.metadata ??
|
|
351
|
+
{});
|
|
352
|
+
this.medusaContext.eventGroupId = metadata.eventGroupId;
|
|
353
|
+
this.medusaContext.parentStepIdempotencyKey =
|
|
354
|
+
metadata.parentStepIdempotencyKey;
|
|
355
|
+
this.medusaContext.preventReleaseEvents = metadata?.preventReleaseEvents;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
exports.LocalWorkflow = LocalWorkflow;
|
|
360
|
+
//# sourceMappingURL=local-workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-workflow.js","sourceRoot":"","sources":["../../src/workflow/local-workflow.ts"],"names":[],"mappings":";;;AACA,0CAQuB;AACvB,mCAAgC;AAChC,gDAQuB;AACvB,8EAAyE;AACzE,yDAI2B;AAO3B,MAAa,aAAa;IASxB,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAA;IACxB,CAAC;IAED,IAAI,SAAS,CAAC,aAA+C;QAC3D,IAAI,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAA;IACtC,CAAC;IAED,YACE,UAAkB,EAClB,aAAgD;QAfxC,kBAAa,GAAqC,EAAE,CAAA;QAiB5D,MAAM,cAAc,GAAG,kCAAe,CAAC,WAAW,CAAC,UAAU,CAAC,CAAA;QAC9D,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,SAAS,EAC3B,qBAAqB,UAAU,cAAc,CAC9C,CAAA;QACH,CAAC;QAED,MAAM,QAAQ,GAAG;YACf,GAAG,cAAc;YACjB,YAAY,EAAE,qCAAuB,CAAC,KAAK,CAAC,cAAc,CAAC,YAAY,CAAC;SACzE,CAAA;QAED,IAAI,CAAC,IAAI,GAAG,IAAI,0CAAmB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;QACnD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;QAE3C,IAAI,CAAC,gBAAgB,CAAC,aAAa,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E,YAAY,CAAC,CAAA;IACrE,CAAC;IAED,YAAY,CAAC,KAAa,EAAE,GAAG,OAAiB;QAC9C,OAAO,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,OAAO,CAAC,CAAA;IAClD,CAAC;IAED,YAAY,CAAC,MAAc,EAAE,WAAY;QACvC,OAAO,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;IACpD,CAAC;IAED,WAAW,CAAC,MAAc;QACxB,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IACtC,CAAC;IAES,aAAa,CAAC,OAAoB,EAAE,MAAc;QAC1D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CACb,uBAAuB,MAAM,+BAA+B,CAC7D,CAAA;QACH,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,WAAuC;QACpD,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACvB,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,EAAE,IAAI,EAAE,CAAA;YACxC,MAAM,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ;gBAC7B,EAAE,CAA0C,CAAA;YAC9C,IAAI,CAAC,aAAa,CAAC,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAA;YACvD,IAAI,CAAC,aAAa,CAAC,wBAAwB;gBACzC,QAAQ,CAAC,wBAAwB,CAAA;YACnC,IAAI,CAAC,aAAa,CAAC,oBAAoB,GAAG,QAAQ,EAAE,oBAAoB,CAAA;QAC1E,CAAC;IACH,CAAC;CACF;AA/iBD,sCA+iBC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IDistributedSchedulerStorage } from "../transaction";
|
|
2
|
+
import { WorkflowDefinition } from "./workflow-manager";
|
|
3
|
+
declare class WorkflowScheduler {
|
|
4
|
+
private static storage;
|
|
5
|
+
static setStorage(storage: IDistributedSchedulerStorage): void;
|
|
6
|
+
scheduleWorkflow(workflow: WorkflowDefinition): Promise<void>;
|
|
7
|
+
clearWorkflow(workflow: WorkflowDefinition): Promise<void>;
|
|
8
|
+
clear(): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
declare const GlobalWorkflowScheduler: typeof WorkflowScheduler;
|
|
11
|
+
export { GlobalWorkflowScheduler as WorkflowScheduler };
|
|
12
|
+
//# sourceMappingURL=scheduler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../src/workflow/scheduler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,4BAA4B,EAAoB,MAAM,gBAAgB,CAAA;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAEvD,cAAM,iBAAiB;IACrB,OAAO,CAAC,MAAM,CAAC,OAAO,CAA8B;WACtC,UAAU,CAAC,OAAO,EAAE,4BAA4B;IAIjD,gBAAgB,CAAC,QAAQ,EAAE,kBAAkB;IAuB7C,aAAa,CAAC,QAAQ,EAAE,kBAAkB;IAI1C,KAAK;CAGnB;AAGD,QAAA,MAAM,uBAAuB,EACC,OAAO,iBAAiB,CAAA;AAEtD,OAAO,EAAE,uBAAuB,IAAI,iBAAiB,EAAE,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkflowScheduler = void 0;
|
|
4
|
+
const utils_1 = require("@8medusa/utils");
|
|
5
|
+
class WorkflowScheduler {
|
|
6
|
+
static setStorage(storage) {
|
|
7
|
+
this.storage = storage;
|
|
8
|
+
}
|
|
9
|
+
async scheduleWorkflow(workflow) {
|
|
10
|
+
const schedule = workflow.options?.schedule;
|
|
11
|
+
if (!schedule) {
|
|
12
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_ARGUMENT, "Workflow schedule is not defined while registering a scheduled workflow");
|
|
13
|
+
}
|
|
14
|
+
const normalizedSchedule = typeof schedule === "string"
|
|
15
|
+
? {
|
|
16
|
+
cron: schedule,
|
|
17
|
+
concurrency: "forbid",
|
|
18
|
+
}
|
|
19
|
+
: {
|
|
20
|
+
concurrency: "forbid",
|
|
21
|
+
...schedule,
|
|
22
|
+
};
|
|
23
|
+
await WorkflowScheduler.storage.schedule(workflow.id, normalizedSchedule);
|
|
24
|
+
}
|
|
25
|
+
async clearWorkflow(workflow) {
|
|
26
|
+
await WorkflowScheduler.storage.remove(workflow.id);
|
|
27
|
+
}
|
|
28
|
+
async clear() {
|
|
29
|
+
await WorkflowScheduler.storage.removeAll();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
global.WorkflowScheduler ??= WorkflowScheduler;
|
|
33
|
+
const GlobalWorkflowScheduler = global.WorkflowScheduler;
|
|
34
|
+
exports.WorkflowScheduler = GlobalWorkflowScheduler;
|
|
35
|
+
//# sourceMappingURL=scheduler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../../src/workflow/scheduler.ts"],"names":[],"mappings":";;;AAAA,0CAA4C;AAI5C,MAAM,iBAAiB;IAEd,MAAM,CAAC,UAAU,CAAC,OAAqC;QAC5D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAEM,KAAK,CAAC,gBAAgB,CAAC,QAA4B;QACxD,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAA;QAC3C,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,gBAAgB,EAClC,yEAAyE,CAC1E,CAAA;QACH,CAAC;QAED,MAAM,kBAAkB,GACtB,OAAO,QAAQ,KAAK,QAAQ;YAC1B,CAAC,CAAC;gBACE,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,QAAQ;aACtB;YACH,CAAC,CAAC;gBACE,WAAW,EAAE,QAAQ;gBACrB,GAAG,QAAQ;aACZ,CAAA;QAEP,MAAM,iBAAiB,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE,kBAAkB,CAAC,CAAA;IAC3E,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,QAA4B;QACrD,MAAM,iBAAiB,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IACrD,CAAC;IAEM,KAAK,CAAC,KAAK;QAChB,MAAM,iBAAiB,CAAC,OAAO,CAAC,SAAS,EAAE,CAAA;IAC7C,CAAC;CACF;AAED,MAAM,CAAC,iBAAiB,KAAK,iBAAiB,CAAA;AAC9C,MAAM,uBAAuB,GAC3B,MAAM,CAAC,iBAA6C,CAAA;AAElB,oDAAiB"}
|