@medusajs/workflow-engine-redis 0.0.3 → 0.0.4-next-20240425093236

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  import { moduleDefinition } from "./module-definition";
2
2
  export default moduleDefinition;
3
- export declare const runMigrations: ({ options, logger, }?: Pick<import("@medusajs/modules-sdk").LoaderOptions<import("@medusajs/modules-sdk").ModuleServiceInitializeOptions>, "options" | "logger"> | undefined) => Promise<void>;
4
- export declare const revertMigration: ({ options, logger, }?: Pick<import("@medusajs/modules-sdk").LoaderOptions<import("@medusajs/modules-sdk").ModuleServiceInitializeOptions>, "options" | "logger"> | undefined) => Promise<void>;
3
+ export declare const runMigrations: ({ options, logger, }?: Pick<import("@medusajs/modules-sdk").LoaderOptions<import("@medusajs/modules-sdk").ModuleServiceInitializeOptions>, "logger" | "options"> | undefined) => Promise<void>;
4
+ export declare const revertMigration: ({ options, logger, }?: Pick<import("@medusajs/modules-sdk").LoaderOptions<import("@medusajs/modules-sdk").ModuleServiceInitializeOptions>, "logger" | "options"> | undefined) => Promise<void>;
5
5
  export * from "./initialize";
6
6
  export * from "./loaders";
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
1
  import { LoaderOptions } from "@medusajs/modules-sdk";
2
- declare const _default: ({ container, logger, options, }: LoaderOptions) => Promise<void>;
2
+ declare const _default: ({ container, logger, options, dataLoaderOnly, }: LoaderOptions) => Promise<void>;
3
3
  export default _default;
4
4
  //# sourceMappingURL=redis.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"redis.d.ts","sourceRoot":"","sources":["../../src/loaders/redis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;0DASlD,aAAa,KAAG,QAAQ,IAAI,CAAC;AAJhC,wBA6DC"}
1
+ {"version":3,"file":"redis.d.ts","sourceRoot":"","sources":["../../src/loaders/redis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;0EAUlD,aAAa,KAAG,QAAQ,IAAI,CAAC;AALhC,wBAqEC"}
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const awilix_1 = require("awilix");
7
7
  const ioredis_1 = __importDefault(require("ioredis"));
8
- exports.default = async ({ container, logger, options, }) => {
8
+ exports.default = async ({ container, logger, options, dataLoaderOnly, }) => {
9
9
  const { url, options: redisOptions, pubsub, } = options?.redis;
10
10
  // TODO: get default from ENV VAR
11
11
  if (!url) {
@@ -37,11 +37,18 @@ exports.default = async ({ container, logger, options, }) => {
37
37
  logger?.error(`An error occurred while connecting to Redis PubSub in module 'workflow-engine-redis': ${err}`);
38
38
  }
39
39
  container.register({
40
+ partialLoading: (0, awilix_1.asValue)(true),
40
41
  redisConnection: (0, awilix_1.asValue)(connection),
41
42
  redisWorkerConnection: (0, awilix_1.asValue)(workerConnection),
42
43
  redisPublisher: (0, awilix_1.asValue)(redisPublisher),
43
44
  redisSubscriber: (0, awilix_1.asValue)(redisSubscriber),
44
45
  redisQueueName: (0, awilix_1.asValue)(queueName),
46
+ redisDisconnectHandler: (0, awilix_1.asValue)(async () => {
47
+ connection.disconnect();
48
+ workerConnection.disconnect();
49
+ redisPublisher.disconnect();
50
+ redisSubscriber.disconnect();
51
+ }),
45
52
  });
46
53
  };
47
54
  async function getConnection(url, redisOptions) {
@@ -49,6 +56,8 @@ async function getConnection(url, redisOptions) {
49
56
  lazyConnect: true,
50
57
  ...(redisOptions ?? {}),
51
58
  });
52
- await connection.connect();
59
+ await new Promise(async (resolve) => {
60
+ await connection.connect(resolve);
61
+ });
53
62
  return connection;
54
63
  }
@@ -1,5 +1,6 @@
1
- declare const _default: ({ container }: {
1
+ declare const _default: ({ container, dataLoaderOnly }: {
2
2
  container: any;
3
+ dataLoaderOnly: any;
3
4
  }) => Promise<void>;
4
5
  export default _default;
5
6
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/loaders/utils.ts"],"names":[],"mappings":";;MAGsC,QAAQ,IAAI,CAAC;AAAnD,wBAMC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/loaders/utils.ts"],"names":[],"mappings":";;;MAGsD,QAAQ,IAAI,CAAC;AAAnE,wBAOC"}
@@ -2,8 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const awilix_1 = require("awilix");
4
4
  const utils_1 = require("../utils");
5
- exports.default = async ({ container }) => {
5
+ exports.default = async ({ container, dataLoaderOnly }) => {
6
6
  container.register({
7
7
  redisDistributedTransactionStorage: (0, awilix_1.asClass)(utils_1.RedisDistributedTransactionStorage).singleton(),
8
+ dataLoaderOnly: (0, awilix_1.asValue)(!!dataLoaderOnly),
8
9
  });
9
10
  };
@@ -1,5 +1,5 @@
1
1
  import { DistributedTransaction, DistributedTransactionEvents, TransactionStep } from "@medusajs/orchestration";
2
- import { ContainerLike, Context } from "@medusajs/types";
2
+ import { ContainerLike, Context, Logger } from "@medusajs/types";
3
3
  import { FlowRunOptions, ReturnWorkflow } from "@medusajs/workflows-sdk";
4
4
  import Redis from "ioredis";
5
5
  import type { RedisDistributedTransactionStorage } from "../utils";
@@ -44,12 +44,19 @@ export declare class WorkflowOrchestratorService {
44
44
  protected redisPublisher: Redis;
45
45
  protected redisSubscriber: Redis;
46
46
  private subscribers;
47
- constructor({ redisDistributedTransactionStorage, redisPublisher, redisSubscriber, }: {
47
+ private activeStepsCount;
48
+ private logger;
49
+ protected redisDistributedTransactionStorage_: RedisDistributedTransactionStorage;
50
+ constructor({ dataLoaderOnly, redisDistributedTransactionStorage, redisPublisher, redisSubscriber, logger, }: {
51
+ dataLoaderOnly: boolean;
48
52
  redisDistributedTransactionStorage: RedisDistributedTransactionStorage;
49
53
  workflowOrchestratorService: WorkflowOrchestratorService;
50
54
  redisPublisher: Redis;
51
55
  redisSubscriber: Redis;
56
+ logger: Logger;
52
57
  });
58
+ onApplicationShutdown(): Promise<void>;
59
+ onApplicationPrepareShutdown(): Promise<void>;
53
60
  run<T = unknown>(workflowIdOrWorkflow: string | ReturnWorkflow<any, any, any>, options?: WorkflowOrchestratorRunOptions<T>, sharedContext?: Context): Promise<any>;
54
61
  getRunningTransaction(workflowId: string, transactionId: string, options?: WorkflowOrchestratorRunOptions<undefined>, sharedContext?: Context): Promise<DistributedTransaction>;
55
62
  setStepSuccess<T = unknown>({ idempotencyKey, stepResponse, options, }: {
@@ -1 +1 @@
1
- {"version":3,"file":"workflow-orchestrator.d.ts","sourceRoot":"","sources":["../../src/services/workflow-orchestrator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,4BAA4B,EAE5B,eAAe,EAChB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAmB,MAAM,iBAAiB,CAAA;AAEzE,OAAO,EACL,cAAc,EAEd,cAAc,EACf,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,MAAM,SAAS,CAAA;AAE3B,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAA;AAElE,MAAM,MAAM,8BAA8B,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,GAAG;IAClE,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,SAAS,CAAC,EAAE,aAAa,CAAA;CAC1B,CAAA;AAED,KAAK,0BAA0B,CAAC,CAAC,IAAI,IAAI,CACvC,8BAA8B,CAAC,CAAC,CAAC,EACjC,eAAe,GAAG,OAAO,CAC1B,CAAA;AAED,KAAK,mBAAmB,GAAG;IACzB,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;IACrB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,QAAQ,GAAG,YA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AE,GAAG,CAAC,EAC5D,OAAO,CAAC,EAAE,8BAA8B,CAAC,CAAC,CAAC,EAC1B,aAAa,GAAE,OAAY;IAiExC,qBAAqB,CACzB,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE,8BAA8B,CAAC,SAAS,CAAC,EAClC,aAAa,GAAE,OAAY,GAC3C,OAAO,CAAC,sBAAsB,CAAC;IA2B5B,cAAc,CAAC,CAAC,GAAG,OAAO,EAC9B,EACE,cAAc,EACd,YAAY,EACZ,OAAO,GACR,EAAE;QACD,cAAc,EAAE,MAAM,GAAG,mBAAmB,CAAA;QAC5C,YAAY,EAAE,OAAO,CAAA;QACrB,OAAO,CAAC,EAAE,0BAA0B,CAAC,CAAC,CAAC,CAAA;KACxC,EACgB,aAAa,GAAE,OAAY;IAkDxC,cAAc,CAAC,CAAC,GAAG,OAAO,EAC9B,EACE,cAAc,EACd,YAAY,EACZ,OAAO,GACR,EAAE;QACD,cAAc,EAAE,MAAM,GAAG,mBAAmB,CAAA;QAC5C,YAAY,EAAE,OAAO,CAAA;QACrB,OAAO,CAAC,EAAE,0BAA0B,CAAC,CAAC,CAAC,CAAA;KACxC,EACgB,aAAa,GAAE,OAAY;IAkD9C,SAAS,CACP,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,EAAE,gBAAgB,EACxD,aAAa,GAAE,OAAY;IAuC9C,WAAW,CACT,EAAE,UAAU,EAAE,aAAa,EAAE,cAAc,EAAE,EAAE,kBAAkB,EAChD,aAAa,GAAE,OAAY;YAiChC,MAAM;IAuDpB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,mBAAmB;IAyF3B,OAAO,CAAC,2BAA2B;CA+BpC"}
1
+ {"version":3,"file":"workflow-orchestrator.d.ts","sourceRoot":"","sources":["../../src/services/workflow-orchestrator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,4BAA4B,EAE5B,eAAe,EAChB,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AO,GACR,EAAE;QACD,cAAc,EAAE,MAAM,GAAG,mBAAmB,CAAA;QAC5C,YAAY,EAAE,OAAO,CAAA;QACrB,OAAO,CAAC,EAAE,0BAA0B,CAAC,CAAC,CAAC,CAAA;KACxC,EACgB,aAAa,GAAE,OAAY;IAkDxC,cAAc,CAAC,CAAC,GAAG,OAAO,EAC9B,EACE,cAAc,EACd,YAAY,EACZ,OAAO,GACR,EAAE;QACD,cAAc,EAAE,MAAM,GAAG,mBAAmB,CAAA;QAC5C,YAAY,EAAE,OAAO,CAAA;QACrB,OAAO,CAAC,EAAE,0BAA0B,CAAC,CAAC,CAAC,CAAA;KACxC,EACgB,aAAa,GAAE,OAAY;IAkD9C,SAAS,CACP,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,EAAE,gBAAgB,EACxD,aAAa,GAAE,OAAY;IAuC9C,WAAW,CACT,EAAE,UAAU,EAAE,aAAa,EAAE,cAAc,EAAE,EAAE,kBAAkB,EAChD,aAAa,GAAE,OAAY;YAiChC,MAAM;IAuDpB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,mBAAmB;IAkH3B,OAAO,CAAC,2BAA2B;CA+BpC"}
@@ -19,18 +19,34 @@ const workflows_sdk_1 = require("@medusajs/workflows-sdk");
19
19
  const ulid_1 = require("ulid");
20
20
  const AnySubscriber = "any";
21
21
  class WorkflowOrchestratorService {
22
- constructor({ redisDistributedTransactionStorage, redisPublisher, redisSubscriber, }) {
22
+ constructor({ dataLoaderOnly, redisDistributedTransactionStorage, redisPublisher, redisSubscriber, logger, }) {
23
23
  this.instanceId = (0, ulid_1.ulid)();
24
24
  this.subscribers = new Map();
25
+ this.activeStepsCount = 0;
25
26
  this.redisPublisher = redisPublisher;
26
27
  this.redisSubscriber = redisSubscriber;
28
+ this.logger = logger;
27
29
  redisDistributedTransactionStorage.setWorkflowOrchestratorService(this);
28
- orchestration_1.DistributedTransaction.setStorage(redisDistributedTransactionStorage);
30
+ if (!dataLoaderOnly) {
31
+ orchestration_1.DistributedTransaction.setStorage(redisDistributedTransactionStorage);
32
+ }
33
+ this.redisDistributedTransactionStorage_ =
34
+ redisDistributedTransactionStorage;
29
35
  this.redisSubscriber.on("message", async (_, message) => {
30
36
  const { instanceId, data } = JSON.parse(message);
31
37
  await this.notify(data, false, instanceId);
32
38
  });
33
39
  }
40
+ async onApplicationShutdown() {
41
+ await this.redisDistributedTransactionStorage_.onApplicationShutdown();
42
+ }
43
+ async onApplicationPrepareShutdown() {
44
+ // eslint-disable-next-line max-len
45
+ await this.redisDistributedTransactionStorage_.onApplicationPrepareShutdown();
46
+ while (this.activeStepsCount > 0) {
47
+ await new Promise((resolve) => setTimeout(resolve, 1000));
48
+ }
49
+ }
34
50
  async run(workflowIdOrWorkflow, options, sharedContext = {}) {
35
51
  let { input, context, transactionId, resultFrom, throwOnError, events: eventHandlers, container, } = options ?? {};
36
52
  const workflowId = (0, utils_1.isString)(workflowIdOrWorkflow)
@@ -286,25 +302,47 @@ class WorkflowOrchestratorService {
286
302
  },
287
303
  onStepBegin: async ({ step, transaction }) => {
288
304
  customEventHandlers?.onStepBegin?.({ step, transaction });
305
+ this.activeStepsCount++;
289
306
  await notify({ eventType: "onStepBegin", step });
290
307
  },
291
308
  onStepSuccess: async ({ step, transaction }) => {
292
- const response = transaction.getContext().invoke[step.id];
309
+ const stepName = step.definition.action;
310
+ const response = await (0, workflows_sdk_1.resolveValue)(transaction.getContext().invoke[stepName], transaction);
293
311
  customEventHandlers?.onStepSuccess?.({ step, transaction, response });
294
312
  await notify({ eventType: "onStepSuccess", step, response });
313
+ this.activeStepsCount--;
295
314
  },
296
315
  onStepFailure: async ({ step, transaction }) => {
297
- const errors = transaction.getErrors(orchestration_1.TransactionHandlerType.INVOKE)[step.id];
316
+ const stepName = step.definition.action;
317
+ const errors = transaction
318
+ .getErrors(orchestration_1.TransactionHandlerType.INVOKE)
319
+ .filter((err) => err.action === stepName);
298
320
  customEventHandlers?.onStepFailure?.({ step, transaction, errors });
299
321
  await notify({ eventType: "onStepFailure", step, errors });
322
+ this.activeStepsCount--;
323
+ },
324
+ onStepAwaiting: async ({ step, transaction }) => {
325
+ customEventHandlers?.onStepAwaiting?.({ step, transaction });
326
+ await notify({ eventType: "onStepAwaiting", step });
327
+ if (!step.definition.backgroundExecution) {
328
+ this.activeStepsCount--;
329
+ }
300
330
  },
301
331
  onCompensateStepSuccess: async ({ step, transaction }) => {
302
- const response = transaction.getContext().compensate[step.id];
303
- customEventHandlers?.onStepSuccess?.({ step, transaction, response });
332
+ const stepName = step.definition.action;
333
+ const response = transaction.getContext().compensate[stepName];
334
+ customEventHandlers?.onCompensateStepSuccess?.({
335
+ step,
336
+ transaction,
337
+ response,
338
+ });
304
339
  await notify({ eventType: "onCompensateStepSuccess", step, response });
305
340
  },
306
341
  onCompensateStepFailure: async ({ step, transaction }) => {
307
- const errors = transaction.getErrors(orchestration_1.TransactionHandlerType.COMPENSATE)[step.id];
342
+ const stepName = step.definition.action;
343
+ const errors = transaction
344
+ .getErrors(orchestration_1.TransactionHandlerType.COMPENSATE)
345
+ .filter((err) => err.action === stepName);
308
346
  customEventHandlers?.onStepFailure?.({ step, transaction, errors });
309
347
  await notify({ eventType: "onCompensateStepFailure", step, errors });
310
348
  },
@@ -5,14 +5,20 @@ type InjectedDependencies = {
5
5
  baseRepository: DAL.RepositoryService;
6
6
  workflowExecutionService: ModulesSdkTypes.InternalModuleService<any>;
7
7
  workflowOrchestratorService: WorkflowOrchestratorService;
8
+ redisDisconnectHandler: () => Promise<void>;
8
9
  };
9
10
  export declare class WorkflowsModuleService implements IWorkflowEngineService {
10
11
  protected readonly moduleDeclaration: InternalModuleDeclaration;
11
12
  protected baseRepository_: DAL.RepositoryService;
12
13
  protected workflowExecutionService_: ModulesSdkTypes.InternalModuleService<any>;
13
14
  protected workflowOrchestratorService_: WorkflowOrchestratorService;
14
- constructor({ baseRepository, workflowExecutionService, workflowOrchestratorService, }: InjectedDependencies, moduleDeclaration: InternalModuleDeclaration);
15
+ protected redisDisconnectHandler_: () => Promise<void>;
16
+ constructor({ baseRepository, workflowExecutionService, workflowOrchestratorService, redisDisconnectHandler, }: InjectedDependencies, moduleDeclaration: InternalModuleDeclaration);
15
17
  __joinerConfig(): ModuleJoinerConfig;
18
+ __hooks: {
19
+ onApplicationShutdown: () => Promise<void>;
20
+ onApplicationPrepareShutdown: () => Promise<void>;
21
+ };
16
22
  retrieveWorkflowExecution(idOrObject: string | {
17
23
  workflow_id: string;
18
24
  transaction_id: string;
@@ -1 +1 @@
1
- {"version":3,"file":"workflows-module.d.ts","sourceRoot":"","sources":["../../src/services/workflows-module.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,GAAG,EACH,UAAU,EACV,yBAAyB,EACzB,kBAAkB,EAClB,eAAe,EAChB,MAAM,iBAAiB,CAAA;AAQxB,OAAO,KAAK,EACV,sBAAsB,EACtB,cAAc,EACd,2BAA2B,EAC3B,yBAAyB,EAC1B,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAA;AAGvD,KAAK,oBAAoB,GAAG;IAC1B,cAAc,EAAE,GAAG,CAAC,iBAAiB,CAAA;IACrC,wBAAwB,EAAE,eAAe,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAA;IACpE,2BAA2B,EAAE,2BAA2B,CAAA;CACzD,CAAA;AAED,qBAAa,sBAAuB,YAAW,sBAAsB;IAWjE,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,yBAAyB;IAVjE,SAAS,CAAC,eAAe,EAAE,GAAG,CAAC,iBAAiB,CAAA;IAChD,SAAS,CAAC,yBAAyB,EAAE,eAAe,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAA;IAC/E,SAAS,CAAC,4BAA4B,EAAE,2BAA2B,CAAA;gBAGjE,EACE,cAAc,EACd,wBAAwB,EACxB,2BAA2B,GAC5B,EAAE,oBAAoB,EACJ,iBAAiB,EAAE,yBAAyB;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AM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAC9B,EACgB,OAAO,GAAE,OAAY;IAalC,cAAc,CAClB,EACE,cAAc,EACd,YAAY,EACZ,OAAO,GACR,EAAE;QACD,cAAc,EAAE,MAAM,GAAG,MAAM,CAAA;QAC/B,YAAY,EAAE,OAAO,CAAA;QACrB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAC9B,EACgB,OAAO,GAAE,OAAY;IAalC,SAAS,CACb,IAAI,EAAE;QACJ,UAAU,EAAE,MAAM,CAAA;QAClB,aAAa,CAAC,EAAE,MAAM,CAAA;QACtB,UAAU,EAAE,QAAQ,CAAA;QACpB,YAAY,CAAC,EAAE,MAAM,CAAA;KACtB,EACgB,OAAO,GAAE,OAAY;IAMlC,WAAW,CACf,IAAI,EAAE;QACJ,UAAU,EAAE,MAAM,CAAA;QAClB,aAAa,CAAC,EAAE,MAAM,CAAA;QACtB,cAAc,EAAE,MAAM,GAAG,QAAQ,CAAA;KAClC,EACgB,OAAO,GAAE,OAAY;CAIzC"}
1
+ {"version":3,"file":"workflows-module.d.ts","sourceRoot":"","sources":["../../src/services/workflows-module.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,GAAG,EACH,UAAU,EACV,yBAAyB,EACzB,kBAAkB,EAClB,eAAe,EAChB,MAAM,iBAAiB,CAAA;AAQxB,OAAO,KAAK,EACV,sBAAsB,EACtB,cAAc,EACd,2BAA2B,EAC3B,yBAAyB,EAC1B,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAA;AAGvD,KAAK,oBAAoB,GAAG;IAC1B,cAAc,EAAE,GAAG,CAAC,iBAAiB,CAAA;IACrC,wBAAwB,EAAE,eAAe,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAA;IACpE,2BAA2B,EAAE,2BAA2B,CAAA;IACxD,sBAAsB,EAAE,MAAM,OAAO,CAAC,IAAI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("@medusajs/utils");
18
18
  const joiner_config_1 = require("../joiner-config");
19
19
  class WorkflowsModuleService {
20
- constructor({ baseRepository, workflowExecutionService, workflowOrchestratorService, }, moduleDeclaration) {
20
+ constructor({ baseRepository, workflowExecutionService, workflowOrchestratorService, redisDisconnectHandler, }, moduleDeclaration) {
21
21
  this.moduleDeclaration = moduleDeclaration;
22
+ this.__hooks = {
23
+ onApplicationShutdown: async () => {
24
+ await this.workflowOrchestratorService_.onApplicationShutdown();
25
+ await this.redisDisconnectHandler_();
26
+ },
27
+ onApplicationPrepareShutdown: async () => {
28
+ await this.workflowOrchestratorService_.onApplicationPrepareShutdown();
29
+ },
30
+ };
22
31
  this.baseRepository_ = baseRepository;
23
32
  this.workflowExecutionService_ = workflowExecutionService;
24
33
  this.workflowOrchestratorService_ = workflowOrchestratorService;
34
+ this.redisDisconnectHandler_ = redisDisconnectHandler;
25
35
  }
26
36
  __joinerConfig() {
27
37
  return joiner_config_1.joinerConfig;
@@ -90,17 +100,17 @@ class WorkflowsModuleService {
90
100
  return ret;
91
101
  }
92
102
  async getRunningTransaction(workflowId, transactionId, context = {}) {
93
- return this.workflowOrchestratorService_.getRunningTransaction(workflowId, transactionId, context);
103
+ return await this.workflowOrchestratorService_.getRunningTransaction(workflowId, transactionId, context);
94
104
  }
95
105
  async setStepSuccess({ idempotencyKey, stepResponse, options, }, context = {}) {
96
- return this.workflowOrchestratorService_.setStepSuccess({
106
+ return await this.workflowOrchestratorService_.setStepSuccess({
97
107
  idempotencyKey,
98
108
  stepResponse,
99
109
  options,
100
110
  }, context);
101
111
  }
102
112
  async setStepFailure({ idempotencyKey, stepResponse, options, }, context = {}) {
103
- return this.workflowOrchestratorService_.setStepFailure({
113
+ return await this.workflowOrchestratorService_.setStepFailure({
104
114
  idempotencyKey,
105
115
  stepResponse,
106
116
  options,
@@ -14,6 +14,8 @@ export declare class RedisDistributedTransactionStorage extends DistributedTrans
14
14
  redisWorkerConnection: Redis;
15
15
  redisQueueName: string;
16
16
  });
17
+ onApplicationPrepareShutdown(): Promise<void>;
18
+ onApplicationShutdown(): Promise<void>;
17
19
  setWorkflowOrchestratorService(workflowOrchestratorService: any): void;
18
20
  private saveToDb;
19
21
  private deleteFromDb;
@@ -1 +1 @@
1
- {"version":3,"file":"workflow-orchestrator-storage.d.ts","sourceRoot":"","sources":["../../src/utils/workflow-orchestrator-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,6BAA6B,EAC7B,qBAAqB,EACrB,eAAe,EAChB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAIjD,OAAO,KAAK,MAAM,SAAS,CAAA;AAS3B,qBAAa,kCAAmC,SAAQ,6BAA6B;IACnF,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAU;IAC5C,OAAO,CAAC,yBAAyB,CAA4C;IAC7E,OAAO,CAAC,4BAA4B,CAA6B;IAEjE,OAAO,CAAC,WAAW,CAAO;IAC1B,OAAO,CAAC,KAAK,CAAO;IACpB,OAAO,CAAC,MAAM,CAAQ;gBAEV,EACV,wBAAwB,EACxB,eAAe,EACf,qBAAqB,EACrB,cAAc,GACf,EAAE;QACD,wBAAwB,EAAE,eAAe,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAA;QACpE,eAAe,EAAE,KAAK,CAAA;QACtB,qBAAqB,EAAE,KAAK,CAAA;QAC5B,cAAc,EAAE,MAAM,CAAA;KACvB;IA4BD,8BAA8B,CAAC,2BAA2B,KAAA;YAI5C,QAAQ;YAeR,YAAY;YASZ,kBAAkB;IAuB1B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;IAM5D,IAAI,IAAI,OAAO,CAAC,qBAAqB,EAAE,CAAC;IAcxC,IAAI,CACR,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,qBAAqB,EAC3B,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,IAAI,CAAC;IAgDV,aAAa,CACjB,WAAW,EAAE,sBAAsB,EACnC,IAAI,EAAE,eAAe,EACrB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC;IAgBV,UAAU,CACd,WAAW,EAAE,sBAAsB,EACnC,IAAI,EAAE,eAAe,GACpB,OAAO,CAAC,IAAI,CAAC;IAIV,0BAA0B,CAC9B,WAAW,EAAE,sBAAsB,EACnC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC;IAeV,uBAAuB,CAC3B,WAAW,EAAE,sBAAsB,GAClC,OAAO,CAAC,IAAI,CAAC;IAIV,mBAAmB,CACvB,WAAW,EAAE,sBAAsB,EACnC,IAAI,EAAE,eAAe,EACrB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC;IAgBV,gBAAgB,CACpB,WAAW,EAAE,sBAAsB,EACnC,IAAI,EAAE,eAAe,GACpB,OAAO,CAAC,IAAI,CAAC;IAIhB,OAAO,CAAC,QAAQ;YAcF,SAAS;CAYxB"}
1
+ {"version":3,"file":"workflow-orchestrator-storage.d.ts","sourceRoot":"","sources":["../../src/utils/workflow-orchestrator-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,6BAA6B,EAC7B,qBAAqB,EACrB,eAAe,EAChB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAIjD,OAAO,KAAK,MAAM,SAAS,CAAA;AAS3B,qBAAa,kCAAmC,SAAQ,6BAA6B;IACnF,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAU;IAC5C,OAAO,CAAC,yBAAyB,CAA4C;IAC7E,OAAO,CAAC,4BAA4B,CAA6B;IAEjE,OAAO,CAAC,WAAW,CAAO;IAC1B,OAAO,CAAC,KAAK,CAAO;IACpB,OAAO,C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IAAI,EAAE,eAAe,GACpB,OAAO,CAAC,IAAI,CAAC;IAIhB,OAAO,CAAC,QAAQ;YAiBF,SAAS;CAYxB"}
@@ -28,6 +28,13 @@ class RedisDistributedTransactionStorage extends orchestration_1.DistributedTran
28
28
  }
29
29
  }, { connection: redisWorkerConnection });
30
30
  }
31
+ async onApplicationPrepareShutdown() {
32
+ // Close worker gracefully, i.e. wait for the current jobs to finish
33
+ await this.worker.close();
34
+ }
35
+ async onApplicationShutdown() {
36
+ await this.queue.close();
37
+ }
31
38
  setWorkflowOrchestratorService(workflowOrchestratorService) {
32
39
  this.workflowOrchestratorService_ = workflowOrchestratorService;
33
40
  }
@@ -59,21 +66,6 @@ class RedisDistributedTransactionStorage extends orchestration_1.DistributedTran
59
66
  throwOnError: false,
60
67
  });
61
68
  }
62
- /*private stringifyWithSymbol(key, value) {
63
- if (key === "__type" && typeof value === "symbol") {
64
- return Symbol.keyFor(value)
65
- }
66
-
67
- return value
68
- }
69
-
70
- private jsonWithSymbol(key, value) {
71
- if (key === "__type" && typeof value === "string") {
72
- return Symbol.for(value)
73
- }
74
-
75
- return value
76
- }*/
77
69
  async get(key) {
78
70
  const data = await this.redisClient.get(key);
79
71
  return data ? JSON.parse(data) : undefined;
@@ -133,7 +125,7 @@ class RedisDistributedTransactionStorage extends orchestration_1.DistributedTran
133
125
  transactionId: transaction.transactionId,
134
126
  stepId: step.id,
135
127
  }, {
136
- delay: interval * 1000,
128
+ delay: interval > 0 ? interval * 1000 : undefined,
137
129
  jobId: this.getJobId(JobType.RETRY, transaction, step),
138
130
  removeOnComplete: true,
139
131
  });
@@ -171,7 +163,10 @@ class RedisDistributedTransactionStorage extends orchestration_1.DistributedTran
171
163
  getJobId(type, transaction, step) {
172
164
  const key = [type, transaction.modelId, transaction.transactionId];
173
165
  if (step) {
174
- key.push(step.id);
166
+ key.push(step.id, step.attempts + "");
167
+ if (step.isCompensating()) {
168
+ key.push("compensate");
169
+ }
175
170
  }
176
171
  return key.join(":");
177
172
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medusajs/workflow-engine-redis",
3
- "version": "0.0.3",
3
+ "version": "0.0.4-next-20240425093236",
4
4
  "description": "Medusa Workflow Orchestrator module using Redis to track workflows executions",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  "watch:test": "tsc --build tsconfig.spec.json --watch",
26
26
  "prepublishOnly": "cross-env NODE_ENV=production tsc --build && tsc-alias -p tsconfig.json",
27
27
  "build": "rimraf dist && tsc --build && tsc-alias -p tsconfig.json",
28
- "test": "jest --passWithNoTests --runInBand --bail --forceExit -- src/**/__tests__/**/*.ts",
28
+ "test": "jest --passWithNoTests --runInBand --bail --forceExit -- src",
29
29
  "test:integration": "jest --forceExit -- integration-tests/**/__tests__/**/*.ts",
30
30
  "migration:generate": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:generate",
31
31
  "migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:create --initial",
@@ -37,7 +37,7 @@
37
37
  "@mikro-orm/cli": "5.9.7",
38
38
  "cross-env": "^5.2.1",
39
39
  "jest": "^29.6.3",
40
- "medusa-test-utils": "^1.1.42",
40
+ "medusa-test-utils": "1.1.44-next-20240425093236",
41
41
  "rimraf": "^3.0.2",
42
42
  "ts-jest": "^29.1.1",
43
43
  "ts-node": "^10.9.1",
@@ -45,15 +45,15 @@
45
45
  "typescript": "^5.1.6"
46
46
  },
47
47
  "dependencies": {
48
- "@medusajs/modules-sdk": "^1.12.9",
49
- "@medusajs/types": "^1.11.14",
50
- "@medusajs/utils": "^1.11.7",
51
- "@medusajs/workflows-sdk": "^0.1.4",
48
+ "@medusajs/modules-sdk": "1.12.11-next-20240425093236",
49
+ "@medusajs/types": "1.12.0-next-20240425093236",
50
+ "@medusajs/utils": "1.12.0-next-20240425093236",
51
+ "@medusajs/workflows-sdk": "0.1.6-next-20240425093236",
52
52
  "@mikro-orm/core": "5.9.7",
53
53
  "@mikro-orm/migrations": "5.9.7",
54
54
  "@mikro-orm/postgresql": "5.9.7",
55
55
  "awilix": "^8.0.0",
56
- "bullmq": "^5.1.3",
56
+ "bullmq": "^5.4.2",
57
57
  "dotenv": "^16.4.5",
58
58
  "ioredis": "^5.3.2",
59
59
  "knex": "2.4.2"