diff options
| author | Kagami Sascha Rosylight <saschanaz@outlook.com> | 2024-01-08 04:28:13 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-08 12:28:13 +0900 |
| commit | 0c2118e9630939eb709c84049bdc8e0fbae8ec11 (patch) | |
| tree | 46fcbd78dfabc5e7062db6826207f3fc34c93d61 /packages/backend/src/core/QueueModule.ts | |
| parent | refactor(frontend): extract game engine from vue component (diff) | |
| download | sharkey-0c2118e9630939eb709c84049bdc8e0fbae8ec11.tar.gz sharkey-0c2118e9630939eb709c84049bdc8e0fbae8ec11.tar.bz2 sharkey-0c2118e9630939eb709c84049bdc8e0fbae8ec11.zip | |
refactor: make sure promises are settled before app shutdown (#12942)
👍
Diffstat (limited to 'packages/backend/src/core/QueueModule.ts')
| -rw-r--r-- | packages/backend/src/core/QueueModule.ts | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/packages/backend/src/core/QueueModule.ts b/packages/backend/src/core/QueueModule.ts index 4444dc9787..20a53ff282 100644 --- a/packages/backend/src/core/QueueModule.ts +++ b/packages/backend/src/core/QueueModule.ts @@ -3,12 +3,12 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -import { setTimeout } from 'node:timers/promises'; import { Inject, Module, OnApplicationShutdown } from '@nestjs/common'; import * as Bull from 'bullmq'; import { DI } from '@/di-symbols.js'; import type { Config } from '@/config.js'; import { QUEUE, baseQueueOptions } from '@/queue/const.js'; +import { allSettled } from '@/misc/promise-tracker.js'; import type { Provider } from '@nestjs/common'; import type { DeliverJobData, InboxJobData, EndedPollNotificationJobData, WebhookDeliverJobData, RelationshipJobData } from '../queue/types.js'; @@ -106,14 +106,9 @@ export class QueueModule implements OnApplicationShutdown { ) {} public async dispose(): Promise<void> { - if (process.env.NODE_ENV === 'test') { - // XXX: - // Shutting down the existing connections causes errors on Jest as - // Misskey has asynchronous postgres/redis connections that are not - // awaited. - // Let's wait for some random time for them to finish. - await setTimeout(5000); - } + // Wait for all potential queue jobs + await allSettled(); + // And then close all queues await Promise.all([ this.systemQueue.close(), this.endedPollNotificationQueue.close(), |