Fix creation of redis clients
This commit is contained in:
@ -1,34 +1,14 @@
|
||||
import { env } from './env'
|
||||
|
||||
import { Queue, RedisOptions } from 'bullmq'
|
||||
import Redis from 'ioredis'
|
||||
import { Queue } from 'bullmq'
|
||||
import { mqRedisClient } from './redis'
|
||||
|
||||
const createRSSRefreshFeedQueue = (): Queue | undefined => {
|
||||
if (!env.redis.url) {
|
||||
return undefined
|
||||
}
|
||||
const redisOptions = (): RedisOptions => {
|
||||
if (env.redis.url?.startsWith('rediss://') && env.redis.cert) {
|
||||
return {
|
||||
tls: {
|
||||
ca: env.redis.cert,
|
||||
rejectUnauthorized: false,
|
||||
},
|
||||
maxRetriesPerRequest: null,
|
||||
}
|
||||
}
|
||||
return {
|
||||
maxRetriesPerRequest: null,
|
||||
}
|
||||
}
|
||||
|
||||
const connection = new Redis(env.redis.url ?? '', redisOptions())
|
||||
return new Queue('rssRefreshFeed', { connection })
|
||||
return new Queue('rssRefreshFeed', {
|
||||
connection: mqRedisClient,
|
||||
})
|
||||
}
|
||||
|
||||
const rssRefreshFeedJobQueue = createRSSRefreshFeedQueue()
|
||||
|
||||
export const addRefreshFeedJob = async (jobid: string, payload: any) => {
|
||||
const rssRefreshFeedJobQueue = createRSSRefreshFeedQueue()
|
||||
if (!rssRefreshFeedJobQueue) {
|
||||
return false
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
import { Redis } from 'ioredis'
|
||||
import { env } from './env'
|
||||
import { Redis } from 'ioredis'
|
||||
import { RedisOptions } from 'bullmq'
|
||||
|
||||
const url = env.redis.url
|
||||
const cert = env.redis.cert
|
||||
|
||||
@ -15,7 +15,7 @@ import { config, loggers } from 'winston'
|
||||
import { makeApolloServer } from './apollo'
|
||||
import { appDataSource } from './data_source'
|
||||
import { env } from './env'
|
||||
import { redisClient } from './redis'
|
||||
import { redisClient, mqRedisClient } from './redis'
|
||||
import { articleRouter } from './routers/article_router'
|
||||
import { authRouter } from './routers/auth/auth_router'
|
||||
import { mobileAuthRouter } from './routers/auth/mobile/mobile_auth_router'
|
||||
@ -163,6 +163,13 @@ const main = async (): Promise<void> => {
|
||||
console.log('Redis Client Connected:', env.redis.url)
|
||||
}
|
||||
|
||||
// redis for message queue
|
||||
if (env.redis.url) {
|
||||
mqRedisClient?.on('error', (err) => {
|
||||
console.error('Redis Client Error', err)
|
||||
})
|
||||
}
|
||||
|
||||
const { app, apollo, httpServer } = createApp()
|
||||
|
||||
await apollo.start()
|
||||
|
||||
Reference in New Issue
Block a user