2023-03-31 16:36:08 +02:00
|
|
|
import { QueueName } from '@app/domain';
|
2023-06-01 12:32:51 +02:00
|
|
|
import { RegisterQueueOptions } from '@nestjs/bullmq';
|
|
|
|
import { QueueOptions } from 'bullmq';
|
2023-03-31 16:36:08 +02:00
|
|
|
import { RedisOptions } from 'ioredis';
|
|
|
|
|
2023-03-31 22:33:21 +02:00
|
|
|
function parseRedisConfig(): RedisOptions {
|
2023-10-06 23:32:28 +02:00
|
|
|
if (process.env.IMMICH_TEST_ENV == 'true') {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2023-03-31 22:33:21 +02:00
|
|
|
const redisUrl = process.env.REDIS_URL;
|
|
|
|
if (redisUrl && redisUrl.startsWith('ioredis://')) {
|
|
|
|
try {
|
|
|
|
const decodedString = Buffer.from(redisUrl.slice(10), 'base64').toString();
|
|
|
|
return JSON.parse(decodedString);
|
|
|
|
} catch (error) {
|
|
|
|
throw new Error(`Failed to decode redis options: ${error}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
host: process.env.REDIS_HOSTNAME || 'immich_redis',
|
|
|
|
port: parseInt(process.env.REDIS_PORT || '6379'),
|
|
|
|
db: parseInt(process.env.REDIS_DBINDEX || '0'),
|
|
|
|
username: process.env.REDIS_USERNAME || undefined,
|
|
|
|
password: process.env.REDIS_PASSWORD || undefined,
|
|
|
|
path: process.env.REDIS_SOCKET || undefined,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export const redisConfig: RedisOptions = parseRedisConfig();
|
2023-03-30 21:38:55 +02:00
|
|
|
|
2023-06-01 12:32:51 +02:00
|
|
|
export const bullConfig: QueueOptions = {
|
2023-03-30 21:38:55 +02:00
|
|
|
prefix: 'immich_bull',
|
2023-06-01 12:32:51 +02:00
|
|
|
connection: redisConfig,
|
2023-03-30 21:38:55 +02:00
|
|
|
defaultJobOptions: {
|
|
|
|
attempts: 3,
|
|
|
|
removeOnComplete: true,
|
|
|
|
removeOnFail: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-06-01 12:32:51 +02:00
|
|
|
export const bullQueues: RegisterQueueOptions[] = Object.values(QueueName).map((name) => ({ name }));
|