Better handling of cases when redis isnt configured

This commit is contained in:
Jackson Harper 2024-01-12 11:00:05 +08:00
parent d29c26d93b
commit b4ce07efd3

View file

@ -1,31 +1,38 @@
import { env } from './env'
import { Queue } from 'bullmq'
import { Queue, RedisOptions } from 'bullmq'
import Redis from 'ioredis'
const redisOptions = () => {
if (env.redis.url?.startsWith('rediss://') && env.redis.cert) {
const createRSSRefreshFeedQueue = (): Queue | undefined => {
if (!env.redis.url) {
return undefined
}
const redisOptions = (): RedisOptions => {
if (env.redis.url?.startsWith('rediss://') && env.redis.cert) {
return {
tls: {
cert: env.redis.cert?.replace(/\\n/g, '\n'),
rejectUnauthorized: false,
},
maxRetriesPerRequest: null,
}
}
return {
tls: {
cert: env.redis.cert?.replace(/\\n/g, '\n'),
rejectUnauthorized: false,
},
maxRetriesPerRequest: null,
}
}
return {
maxRetriesPerRequest: null,
}
const connection = new Redis(env.redis.url ?? '', redisOptions())
return new Queue('rssRefreshFeed', { connection })
}
const connection = new Redis(env.redis.url ?? '', redisOptions())
export const rssRefreshFeedJobQueue = new Queue('rssRefreshFeed', {
connection,
})
export const addRefreshFeedJob = async (jobid: string, payload: any) => {
return rssRefreshFeedJobQueue.add('rssRefreshFeed', payload, {
const rssRefreshFeedJobQueue = createRSSRefreshFeedQueue()
if (!rssRefreshFeedJobQueue) {
return false
}
return rssRefreshFeedJobQueue?.add('rssRefreshFeed', payload, {
jobId: jobid,
removeOnComplete: true,
removeOnFail: true,