Put cron in a function

This commit is contained in:
Ralfs 2021-04-10 01:26:00 +03:00
parent 91f66571bb
commit 07c080f249
1 changed files with 34 additions and 30 deletions

View File

@ -79,10 +79,11 @@ app.listen(config.port, () => {
sendLogsToDiscord(readyMessage, null);
});
cron.schedule("1 * * * *", async () => {
try {
const runCron = async () => {
const mongoConnection = await MongoClient.connect(config.dbConnectionString, { useUnifiedTopology: true });
const db = mongoConnection.db(config.db);
cron.schedule("1 * * * *", async () => {
try {
const alerts = await db.collection('alerts').find({open: true}).toArray();
const uniqueMangoGroupPks: string[] = [...new Set(alerts.map(alert => alert.mangoGroupPk))];
const mangoGroups:any = await reduceMangoGroups(client, connection, uniqueMangoGroupPks);
@ -110,3 +111,6 @@ cron.schedule("1 * * * *", async () => {
sendLogsToDiscord(null, e);
}
});
}
runCron();