feat: v2 - add worker mode (#6739)

**What**
- Adds support for starting a Medusa process with a worker mode.
- The worker modes supported are "shared", "worker", "server"
- In "worker" mode, API routes are not registered and modules that need to run workers (e.g., event bus redis) can use the flag to conditionally start workers.
- In "server" mode, API routes are registered and workers are not started.
- In "shared" mode, API routes are registered and workers are started. This is great for development.
This commit is contained in:
Sebastian Rindom authored and GitHub committed 2024-03-21 13:08:20 +00:00
1 parent 205573f5e3
commit 56481e683d
11 files changed
+141 -58

No files matched your search

@@ -42,11 +42,14 @@ export default class RedisEventBusService extends AbstractEventBusModuleService
})
// Register our worker to handle emit calls
new Worker(moduleOptions.queueName ?? "events-queue", this.worker_, {
prefix: `${this.constructor.name}`,
...(moduleOptions.workerOptions ?? {}),
connection: eventBusRedisConnection,
})
const shouldStartWorker = moduleDeclaration.worker_mode !== "server"
if (shouldStartWorker) {
new Worker(moduleOptions.queueName ?? "events-queue", this.worker_, {
prefix: `${this.constructor.name}`,
...(moduleOptions.workerOptions ?? {}),
connection: eventBusRedisConnection,
})
}
}
/**