fixed queue and finished initial qm work
This commit is contained in:
parent
52436c69b2
commit
00fbd31364
4 changed files with 45 additions and 56 deletions
|
|
@ -264,26 +264,49 @@ export class Queue {
|
|||
*/
|
||||
async close(): Promise<void> {
|
||||
try {
|
||||
// Close the queue itself
|
||||
await this.bullQueue.close();
|
||||
this.logger.info('Queue closed', { queueName: this.queueName });
|
||||
|
||||
// Close queue events
|
||||
if (this.queueEvents) {
|
||||
await this.queueEvents.close();
|
||||
this.logger.debug('Queue events closed', { queueName: this.queueName });
|
||||
}
|
||||
|
||||
// Close workers first
|
||||
// Close workers first with timeout
|
||||
if (this.workers.length > 0) {
|
||||
await Promise.all(
|
||||
this.workers.map(async worker => {
|
||||
return await worker.close();
|
||||
})
|
||||
);
|
||||
const workerClosePromises = this.workers.map(async (worker, idx) => {
|
||||
try {
|
||||
const closePromise = worker.close();
|
||||
const timeoutPromise = new Promise<void>((resolve) => {
|
||||
setTimeout(() => {
|
||||
this.logger.warn('Worker close timeout, forcing closure', {
|
||||
queueName: this.queueName,
|
||||
workerId: idx
|
||||
});
|
||||
resolve();
|
||||
}, 2000); // 2 second timeout per worker
|
||||
});
|
||||
|
||||
await Promise.race([closePromise, timeoutPromise]);
|
||||
} catch (error) {
|
||||
this.logger.warn('Error closing worker', {
|
||||
queueName: this.queueName,
|
||||
workerId: idx,
|
||||
error
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
await Promise.all(workerClosePromises);
|
||||
this.workers = [];
|
||||
this.logger.debug('Workers closed', { queueName: this.queueName });
|
||||
}
|
||||
|
||||
// Close queue events
|
||||
if (this.queueEvents) {
|
||||
try {
|
||||
await this.queueEvents.close();
|
||||
this.logger.debug('Queue events closed', { queueName: this.queueName });
|
||||
} catch (error) {
|
||||
this.logger.warn('Error closing queue events', { queueName: this.queueName, error });
|
||||
}
|
||||
}
|
||||
|
||||
// Close the queue itself
|
||||
await this.bullQueue.close();
|
||||
this.logger.info('Queue closed', { queueName: this.queueName });
|
||||
} catch (error) {
|
||||
this.logger.error('Error closing queue', { queueName: this.queueName, error });
|
||||
throw error;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue