fix(workflow-engine-redis): Split the queues and respect worker mode for job executions (#11740)
**What** Currently, the workflow engine redis does not make any distinction between worker modes, when starting as server, the engine listen to the queue which contains everything and try to execute the corresponding workflow which does not exists since job workflows are not loaded in server mode. Now, a dedicated queue is created for jobs and the worker is only started if the instance is not in server mode. In order to clean up the old queue, if the old queue trigger a scheduled job then it gets removed from the queue since it will get re added to the new queue by the new worker instances
This commit is contained in:
committed by
GitHub
parent
4f23901fcf
commit
cc8422d3a1
@@ -1,14 +1,15 @@
|
||||
import { LoaderOptions } from "@medusajs/framework/types"
|
||||
import {
|
||||
InternalModuleDeclaration,
|
||||
LoaderOptions,
|
||||
} from "@medusajs/framework/types"
|
||||
import { asValue } from "awilix"
|
||||
import Redis from "ioredis"
|
||||
import { RedisWorkflowsOptions } from "../types"
|
||||
|
||||
export default async ({
|
||||
container,
|
||||
logger,
|
||||
options,
|
||||
dataLoaderOnly,
|
||||
}: LoaderOptions): Promise<void> => {
|
||||
export default async (
|
||||
{ container, logger, options, dataLoaderOnly }: LoaderOptions,
|
||||
moduleDeclaration: InternalModuleDeclaration
|
||||
): Promise<void> => {
|
||||
const {
|
||||
url,
|
||||
options: redisOptions,
|
||||
@@ -25,6 +26,7 @@ export default async ({
|
||||
const cnnPubSub = pubsub ?? { url, options: redisOptions }
|
||||
|
||||
const queueName = options?.queueName ?? "medusa-workflows"
|
||||
const jobQueueName = options?.jobQueueName ?? "medusa-workflows-jobs"
|
||||
|
||||
let connection
|
||||
let redisPublisher
|
||||
@@ -59,12 +61,14 @@ export default async ({
|
||||
}
|
||||
|
||||
container.register({
|
||||
isWorkerMode: asValue(moduleDeclaration.worker_mode !== "server"),
|
||||
partialLoading: asValue(true),
|
||||
redisConnection: asValue(connection),
|
||||
redisWorkerConnection: asValue(workerConnection),
|
||||
redisPublisher: asValue(redisPublisher),
|
||||
redisSubscriber: asValue(redisSubscriber),
|
||||
redisQueueName: asValue(queueName),
|
||||
redisJobQueueName: asValue(jobQueueName),
|
||||
redisDisconnectHandler: asValue(async () => {
|
||||
connection.disconnect()
|
||||
workerConnection.disconnect()
|
||||
|
||||
Reference in New Issue
Block a user