From 18b0848e07375fd5758d5c89256aae42c9cf1370 Mon Sep 17 00:00:00 2001 From: chimpdev Date: Sun, 24 Mar 2024 05:04:59 +0300 Subject: [PATCH] Add conditional cron job listening based on environment --- server/index.js | 1 + server/src/client.js | 10 ++++++---- server/startup/registerCommands.js | 1 + server/startup/unregisterCommands.js | 1 + 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/server/index.js b/server/index.js index 317b902d..3d412072 100644 --- a/server/index.js +++ b/server/index.js @@ -26,6 +26,7 @@ client.create().start(process.env.DISCORD_CLIENT_TOKEN, { checkVoteReminderMetadatas: true, listenEvents: true }, + listenCrons: process.env.NODE_ENV === 'production', registerCommands: false, unregisterCommands: false, }); diff --git a/server/src/client.js b/server/src/client.js index d49e2125..860c4519 100644 --- a/server/src/client.js +++ b/server/src/client.js @@ -78,10 +78,12 @@ module.exports = class Client { if (options.startup.updateClientActivity) this.updateClientActivity(); if (options.startup.checkVoteReminderMetadatas) this.checkVoteReminderMetadatas(); - new CronJob('0 * * * *', this.checkVoiceActivity, null, true, 'Europe/Istanbul'); - new CronJob('59 23 28-31 * *', this.saveMonthlyVotes, null, true, 'Europe/Istanbul'); - new CronJob('0 0 * * *', this.updateClientActivity, null, true, 'Europe/Istanbul'); - new CronJob('0 0 * * *', this.checkVoteReminderMetadatas, null, true, 'Europe/Istanbul'); + if (options.listenCrons) { + new CronJob('0 * * * *', this.checkVoiceActivity, null, true, 'Europe/Istanbul'); + new CronJob('59 23 28-31 * *', this.saveMonthlyVotes, null, true, 'Europe/Istanbul'); + new CronJob('0 0 * * *', this.updateClientActivity, null, true, 'Europe/Istanbul'); + new CronJob('0 0 * * *', this.checkVoteReminderMetadatas, null, true, 'Europe/Istanbul'); + } }); } diff --git a/server/startup/registerCommands.js b/server/startup/registerCommands.js index 718d3b09..9c397b87 100644 --- a/server/startup/registerCommands.js +++ b/server/startup/registerCommands.js @@ -18,6 +18,7 @@ client.create().start(process.env.DISCORD_CLIENT_TOKEN, { checkVoteReminderMetadatas: false, listenEvents: false }, + listenCrons: false, registerCommands: true, unregisterCommands: false }); \ No newline at end of file diff --git a/server/startup/unregisterCommands.js b/server/startup/unregisterCommands.js index 9b00b3a3..3e2023c0 100644 --- a/server/startup/unregisterCommands.js +++ b/server/startup/unregisterCommands.js @@ -18,6 +18,7 @@ client.create().start(process.env.DISCORD_CLIENT_TOKEN, { checkVoteReminderMetadatas: false, listenEvents: false }, + listenCrons: false, registerCommands: false, unregisterCommands: true }); \ No newline at end of file