Use initJobQueue method to initialize JobQueue, flush Redis DB on shutdown timeout
This commit is contained in:
1 parent
e222b13b51
commit
4c2a0fd2d3
3 files changed
+25
-7
No files matched your search
+20
-3
@@ -68,6 +68,8 @@ import ServiceRegistry from "./service/serviceRegistry.js";
|
|||||||
|
|
||||||
import MongoDB from "./db/mongo/MongoDB.js";
|
import MongoDB from "./db/mongo/MongoDB.js";
|
||||||
|
|
||||||
|
import IORedis from "ioredis";
|
||||||
|
|
||||||
const SERVICE_NAME = "Server";
|
const SERVICE_NAME = "Server";
|
||||||
const SHUTDOWN_TIMEOUT = 1000;
|
const SHUTDOWN_TIMEOUT = 1000;
|
||||||
let isShuttingDown = false;
|
let isShuttingDown = false;
|
||||||
@@ -87,12 +89,24 @@ const shutdown = async () => {
|
|||||||
}
|
}
|
||||||
isShuttingDown = true;
|
isShuttingDown = true;
|
||||||
logger.info({ message: "Attempting graceful shutdown" });
|
logger.info({ message: "Attempting graceful shutdown" });
|
||||||
setTimeout(() => {
|
setTimeout(async () => {
|
||||||
logger.error({
|
logger.error({
|
||||||
message: "Could not shut down in time, forcing shutdown",
|
message: "Could not shut down in time, forcing shutdown",
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "shutdown",
|
method: "shutdown",
|
||||||
});
|
});
|
||||||
|
// flush Redis
|
||||||
|
const settings =
|
||||||
|
ServiceRegistry.get(SettingsService.SERVICE_NAME).getSettings() || {};
|
||||||
|
|
||||||
|
const { redisHost = "127.0.0.1", redisPort = 6379 } = settings;
|
||||||
|
const redis = new IORedis({
|
||||||
|
host: redisHost,
|
||||||
|
port: redisPort,
|
||||||
|
});
|
||||||
|
logger.info({ message: "Flushing Redis" });
|
||||||
|
await redis.flushall();
|
||||||
|
logger.info({ message: "Redis flushed" });
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}, SHUTDOWN_TIMEOUT);
|
}, SHUTDOWN_TIMEOUT);
|
||||||
try {
|
try {
|
||||||
@@ -133,10 +147,11 @@ const startApp = async () => {
|
|||||||
const networkService = new NetworkService(axios, ping, logger, http, Docker, net);
|
const networkService = new NetworkService(axios, ping, logger, http, Docker, net);
|
||||||
const statusService = new StatusService(db, logger);
|
const statusService = new StatusService(db, logger);
|
||||||
const notificationService = new NotificationService(emailService, db, logger);
|
const notificationService = new NotificationService(emailService, db, logger);
|
||||||
const jobQueue = await JobQueue.createJobQueue(
|
|
||||||
|
const jobQueue = new JobQueue(
|
||||||
db,
|
db,
|
||||||
networkService,
|
|
||||||
statusService,
|
statusService,
|
||||||
|
networkService,
|
||||||
notificationService,
|
notificationService,
|
||||||
settingsService,
|
settingsService,
|
||||||
logger,
|
logger,
|
||||||
@@ -212,6 +227,8 @@ const startApp = async () => {
|
|||||||
);
|
);
|
||||||
const queueRoutes = new QueueRoutes(queueController);
|
const queueRoutes = new QueueRoutes(queueController);
|
||||||
const statusPageRoutes = new StatusPageRoutes(statusPageController);
|
const statusPageRoutes = new StatusPageRoutes(statusPageController);
|
||||||
|
// Init job queue
|
||||||
|
await jobQueue.initJobQueue();
|
||||||
// Middleware
|
// Middleware
|
||||||
app.use(
|
app.use(
|
||||||
cors()
|
cors()
|
||||||
|
|||||||
Generated
+4
-4
@@ -18,6 +18,7 @@
|
|||||||
"express": "^4.19.2",
|
"express": "^4.19.2",
|
||||||
"handlebars": "^4.7.8",
|
"handlebars": "^4.7.8",
|
||||||
"helmet": "^8.0.0",
|
"helmet": "^8.0.0",
|
||||||
|
"ioredis": "^5.4.2",
|
||||||
"joi": "^17.13.1",
|
"joi": "^17.13.1",
|
||||||
"jsonwebtoken": "9.0.2",
|
"jsonwebtoken": "9.0.2",
|
||||||
"mailersend": "^2.2.0",
|
"mailersend": "^2.2.0",
|
||||||
@@ -3902,10 +3903,9 @@
|
|||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
"node_modules/ioredis": {
|
"node_modules/ioredis": {
|
||||||
"version": "5.4.1",
|
"version": "5.4.2",
|
||||||
"resolved": "https://registry.npmjs.org/ioredis/-/ioredis-5.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/ioredis/-/ioredis-5.4.2.tgz",
|
||||||
"integrity": "sha512-2YZsvl7jopIa1gaePkeMtd9rAcSjOOjPtpcLlOeusyO+XH2SK5ZcT+UCrElPP+WVIInh2TzeI4XW9ENaSLVVHA==",
|
"integrity": "sha512-0SZXGNGZ+WzISQ67QDyZ2x0+wVxjjUndtD8oSeik/4ajifeiRufed8fCb8QW8VMyi4MXcS+UO1k/0NGhvq1PAg==",
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ioredis/commands": "^1.1.1",
|
"@ioredis/commands": "^1.1.1",
|
||||||
"cluster-key-slot": "^1.1.0",
|
"cluster-key-slot": "^1.1.0",
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
"express": "^4.19.2",
|
"express": "^4.19.2",
|
||||||
"handlebars": "^4.7.8",
|
"handlebars": "^4.7.8",
|
||||||
"helmet": "^8.0.0",
|
"helmet": "^8.0.0",
|
||||||
|
"ioredis": "^5.4.2",
|
||||||
"joi": "^17.13.1",
|
"joi": "^17.13.1",
|
||||||
"jsonwebtoken": "9.0.2",
|
"jsonwebtoken": "9.0.2",
|
||||||
"mailersend": "^2.2.0",
|
"mailersend": "^2.2.0",
|
||||||
|
|||||||
Reference in new issue
Block a user