🔧 Fixed the Redis disconnection issue

This commit is contained in:
2024-05-17 01:26:16 -04:00
parent 8dcb17a6a0
commit cc772504ae
9 changed files with 65 additions and 107 deletions

View File

@@ -11,10 +11,10 @@ import {
} from "../utils/uncompression.utils";
import { isNil, isUndefined } from "lodash";
import { pubClient } from "../config/redis.config";
import IORedis from 'ioredis';
import path from "path";
const { MoleculerError } = require("moleculer").Errors;
console.log(process.env.REDIS_URI);
export default class JobQueueService extends Service {
public constructor(public broker: ServiceBroker) {
super(broker);
@@ -24,7 +24,7 @@ export default class JobQueueService extends Service {
mixins: [DbMixin("comics", Comic), BullMqMixin],
settings: {
bullmq: {
client: process.env.REDIS_URI,
client: new IORedis(process.env.REDIS_URI, { maxRetriesPerRequest: null }),
},
},
actions: {

View File

@@ -1,7 +1,6 @@
"use strict";
import { Service, ServiceBroker, ServiceSchema, Context } from "moleculer";
import { JobType } from "moleculer-bullmq";
import { createClient } from "redis";
import { createAdapter } from "@socket.io/redis-adapter";
import Session from "../models/session.model";
import { pubClient, subClient } from "../config/redis.config";
@@ -325,6 +324,22 @@ export default class SocketService extends Service {
},
},
async started() {
this.logger.info("Starting Socket Service...");
this.logger.debug("pubClient:", pubClient);
this.logger.debug("subClient:", subClient);
if (!pubClient || !subClient) {
this.logger.error("Redis clients are not initialized!");
throw new Error("Redis clients are not initialized!");
}
// Additional checks or logic if necessary
if (pubClient.status !== "ready") {
await pubClient.connect();
}
if (subClient.status !== "ready") {
await subClient.connect();
}
this.io.on("connection", async (socket) => {
console.log(
`socket.io server connected to client with session ID: ${socket.id}`

View File

@@ -10,6 +10,7 @@ import { DbMixin } from "../mixins/db.mixin";
import Comic from "../models/comic.model";
import BullMqMixin from "moleculer-bullmq";
const { MoleculerError } = require("moleculer").Errors;
import IORedis from 'ioredis';
export default class ImageTransformation extends Service {
// @ts-ignore
@@ -23,7 +24,7 @@ export default class ImageTransformation extends Service {
mixins: [DbMixin("comics", Comic), BullMqMixin],
settings: {
bullmq: {
client: process.env.REDIS_URI,
client: new IORedis(process.env.REDIS_URI),
},
},
hooks: {},