2023-08-15 02:52:38 +09:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-05-29 11:54:49 +09:00
|
|
|
import type * as Bull from 'bullmq';
|
2023-12-29 14:58:35 +09:00
|
|
|
import type { RedisOptions } from "ioredis";
|
|
|
|
import type { RedisOptionsSource } from '@/config.js';
|
2023-05-29 11:54:49 +09:00
|
|
|
|
|
|
|
export const QUEUE = {
|
|
|
|
DELIVER: 'deliver',
|
|
|
|
INBOX: 'inbox',
|
|
|
|
SYSTEM: 'system',
|
|
|
|
ENDED_POLL_NOTIFICATION: 'endedPollNotification',
|
|
|
|
DB: 'db',
|
|
|
|
RELATIONSHIP: 'relationship',
|
|
|
|
OBJECT_STORAGE: 'objectStorage',
|
|
|
|
WEBHOOK_DELIVER: 'webhookDeliver',
|
|
|
|
};
|
|
|
|
|
2024-01-02 14:42:33 +09:00
|
|
|
export function baseQueueOptions(config: RedisOptions & RedisOptionsSource, queueOptions: Partial<Bull.QueueOptions>, queueName: typeof QUEUE[keyof typeof QUEUE]): Bull.QueueOptions {
|
2023-05-29 11:54:49 +09:00
|
|
|
return {
|
2024-01-02 14:42:33 +09:00
|
|
|
...queueOptions,
|
2023-12-28 05:33:22 +09:00
|
|
|
connection: {
|
2023-12-29 14:58:35 +09:00
|
|
|
...config,
|
2023-12-28 05:33:22 +09:00
|
|
|
maxRetriesPerRequest: null,
|
|
|
|
keyPrefix: undefined,
|
2024-01-02 14:42:33 +09:00
|
|
|
reconnectOnError: (err: Error) => {
|
|
|
|
if ( err.message.includes('READONLY')
|
|
|
|
|| err.message.includes('ETIMEDOUT')
|
|
|
|
|| err.message.includes('Command timed out')
|
|
|
|
) return 2;
|
|
|
|
return 1;
|
|
|
|
},
|
2023-12-28 05:33:22 +09:00
|
|
|
},
|
2023-12-29 14:58:35 +09:00
|
|
|
prefix: config.prefix ? `${config.prefix}:queue:${queueName}` : `queue:${queueName}`,
|
2023-05-29 11:54:49 +09:00
|
|
|
};
|
|
|
|
}
|
2024-01-01 02:57:23 +09:00
|
|
|
|
2024-01-02 14:42:33 +09:00
|
|
|
export function baseWorkerOptions(config: RedisOptions & RedisOptionsSource, workerOptions: Partial<Bull.WorkerOptions>, queueName: typeof QUEUE[keyof typeof QUEUE]): Bull.WorkerOptions {
|
2024-01-01 02:57:23 +09:00
|
|
|
return {
|
2024-01-02 14:42:33 +09:00
|
|
|
...workerOptions,
|
2024-01-01 02:57:23 +09:00
|
|
|
connection: {
|
|
|
|
...config,
|
|
|
|
maxRetriesPerRequest: null,
|
|
|
|
keyPrefix: undefined,
|
2024-01-02 14:42:33 +09:00
|
|
|
reconnectOnError: (err: Error) => {
|
|
|
|
if ( err.message.includes('READONLY')
|
|
|
|
|| err.message.includes('ETIMEDOUT')
|
|
|
|
|| err.message.includes('Command timed out')
|
|
|
|
) return 2;
|
|
|
|
return 1;
|
|
|
|
},
|
2024-01-01 02:57:23 +09:00
|
|
|
},
|
|
|
|
prefix: config.prefix ? `${config.prefix}:queue:${queueName}` : `queue:${queueName}`,
|
|
|
|
};
|
|
|
|
}
|