feat(medusa): workflow engine api (#6330)
What:
Workflow Engine API.
Endpoints for:
- List workflow executions
- Run a workflow
- Set async steps as success or failure
- Retrieve the details of a workflow run
This commit is contained in:
committed by
GitHub
parent
59ab66a773
commit
0c2a460751
@@ -4,11 +4,9 @@ import {
|
||||
TransactionCheckpoint,
|
||||
TransactionStep,
|
||||
} from "@medusajs/orchestration"
|
||||
import { TransactionState } from "@medusajs/utils"
|
||||
import { ModulesSdkTypes } from "@medusajs/types"
|
||||
import {
|
||||
WorkflowOrchestratorService,
|
||||
} from "@services"
|
||||
import { TransactionState } from "@medusajs/utils"
|
||||
import { WorkflowOrchestratorService } from "@services"
|
||||
import { Queue, Worker } from "bullmq"
|
||||
import Redis from "ioredis"
|
||||
|
||||
@@ -21,7 +19,7 @@ enum JobType {
|
||||
// eslint-disable-next-line max-len
|
||||
export class RedisDistributedTransactionStorage extends DistributedTransactionStorage {
|
||||
private static TTL_AFTER_COMPLETED = 60 * 15 // 15 minutes
|
||||
private workflowExecutionService_: ModulesSdkTypes.InternalModuleService<any>
|
||||
private workflowExecutionService_: ModulesSdkTypes.InternalModuleService<any>
|
||||
private workflowOrchestratorService_: WorkflowOrchestratorService
|
||||
|
||||
private redisClient: Redis
|
||||
@@ -34,7 +32,7 @@ export class RedisDistributedTransactionStorage extends DistributedTransactionSt
|
||||
redisWorkerConnection,
|
||||
redisQueueName,
|
||||
}: {
|
||||
workflowExecutionService: ModulesSdkTypes.InternalModuleService<any>,
|
||||
workflowExecutionService: ModulesSdkTypes.InternalModuleService<any>
|
||||
redisConnection: Redis
|
||||
redisWorkerConnection: Redis
|
||||
redisQueueName: string
|
||||
@@ -161,33 +159,28 @@ export class RedisDistributedTransactionStorage extends DistributedTransactionSt
|
||||
})
|
||||
}
|
||||
|
||||
const stringifiedData = JSON.stringify(data, this.stringifyWithSymbol)
|
||||
const parsedData = JSON.parse(stringifiedData)
|
||||
|
||||
if (!hasFinished) {
|
||||
if (ttl) {
|
||||
await this.redisClient.set(
|
||||
key,
|
||||
JSON.stringify(data, this.stringifyWithSymbol),
|
||||
"EX",
|
||||
ttl
|
||||
)
|
||||
await this.redisClient.set(key, stringifiedData, "EX", ttl)
|
||||
} else {
|
||||
await this.redisClient.set(
|
||||
key,
|
||||
JSON.stringify(data, this.stringifyWithSymbol)
|
||||
)
|
||||
await this.redisClient.set(key, stringifiedData)
|
||||
}
|
||||
}
|
||||
|
||||
if (hasFinished && !retentionTime) {
|
||||
await this.deleteFromDb(data)
|
||||
await this.deleteFromDb(parsedData)
|
||||
} else {
|
||||
await this.saveToDb(data)
|
||||
await this.saveToDb(parsedData)
|
||||
}
|
||||
|
||||
if (hasFinished) {
|
||||
// await this.redisClient.del(key)
|
||||
await this.redisClient.set(
|
||||
key,
|
||||
JSON.stringify(data, this.stringifyWithSymbol),
|
||||
stringifiedData,
|
||||
"EX",
|
||||
RedisDistributedTransactionStorage.TTL_AFTER_COMPLETED
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user