chore: medusa shutdown (#6865)
* chore: medusa shutdown * continue * use shutdown * on application shutdown * consume shutdown * more connection close * more cleanup * more cleanup * update lock * revert package * graceful shutdown * Create yellow-apples-attack.md * graceful shutdown * graceful shutdown --------- Co-authored-by: Sebastian Rindom <skrindom@gmail.com> Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
This commit is contained in:
co-authored by
Sebastian Rindom
Riqwan Thamir
parent
0c0b425de7
commit
8fd1488938
@@ -20,8 +20,10 @@ export default class RedisEventBusService extends AbstractEventBusModuleService
|
||||
protected readonly moduleOptions_: EventBusRedisModuleOptions
|
||||
// eslint-disable-next-line max-len
|
||||
protected readonly moduleDeclaration_: InternalModuleDeclaration
|
||||
protected readonly eventBusRedisConnection_: Redis
|
||||
|
||||
protected queue_: Queue
|
||||
protected bullWorker_: Worker
|
||||
|
||||
constructor(
|
||||
{ logger, eventBusRedisConnection }: InjectedDependencies,
|
||||
@@ -32,6 +34,8 @@ export default class RedisEventBusService extends AbstractEventBusModuleService
|
||||
// eslint-disable-next-line prefer-rest-params
|
||||
super(...arguments)
|
||||
|
||||
this.eventBusRedisConnection_ = eventBusRedisConnection
|
||||
|
||||
this.moduleOptions_ = moduleOptions
|
||||
this.logger_ = logger
|
||||
|
||||
@@ -44,14 +48,26 @@ export default class RedisEventBusService extends AbstractEventBusModuleService
|
||||
// Register our worker to handle emit calls
|
||||
const shouldStartWorker = moduleDeclaration.worker_mode !== "server"
|
||||
if (shouldStartWorker) {
|
||||
new Worker(moduleOptions.queueName ?? "events-queue", this.worker_, {
|
||||
prefix: `${this.constructor.name}`,
|
||||
...(moduleOptions.workerOptions ?? {}),
|
||||
connection: eventBusRedisConnection,
|
||||
})
|
||||
this.bullWorker_ = new Worker(
|
||||
moduleOptions.queueName ?? "events-queue",
|
||||
this.worker_,
|
||||
{
|
||||
prefix: `${this.constructor.name}`,
|
||||
...(moduleOptions.workerOptions ?? {}),
|
||||
connection: eventBusRedisConnection,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
__hooks = {
|
||||
onApplicationShutdown: async () => {
|
||||
await this.bullWorker_.close(true)
|
||||
await this.queue_.close()
|
||||
this.eventBusRedisConnection_.disconnect()
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit a single event
|
||||
* @param {string} eventName - the name of the event to be process.
|
||||
|
||||
Reference in New Issue
Block a user