const express = require("express"); const app = express(); const port = 3000; const cron = require("node-cron"); const axios = require("axios"); const { exec } = require("child_process"); app.get("/", (req, res) => { res.json("Scheduler App"); }); cron.schedule( "0 9 * * *", async () => { const module = "Birthday Notification"; try { let res = await axios.get("http://36.66.3.44:7010/birthday-notification"); console.log(module, "success", res.data); } catch (error) { console.error(module, "error", error.message); } }, { timezone: "Asia/Jakarta", } ); cron.schedule( "1 9 * * *", async () => { const module = "Workanniversary"; try { let res = await axios.get( "http://36.66.3.44:7010/workanniversary-notification" ); console.log(module, "success", res.data); } catch (error) { console.error(module, "error", error.message); } }, { timezone: "Asia/Jakarta", } ); cron.schedule( "* * * * *", async () => { exec("sh /home/script/script.sh", (error, stdout, stderr) => { if (error) { console.error( `Gagal menjalankan script Antrisimatupang : ${error.message}` ); return; } if (stderr) { console.error(`Stderr Antrisimatupang : ${stderr}`); return; } console.log(`Output Antrisimatupang: ${stdout}`); }); exec("sh /home/script/script2.sh", (error, stdout, stderr) => { if (error) { console.error( `Gagal menjalankan script antributikemas : ${error.message}` ); return; } if (stderr) { console.error(`Stderr antributikemas : ${stderr}`); return; } console.log(`Output antributikemas: ${stdout}`); }); }, { timezone: "Asia/Jakarta", } ); cron.schedule( "0-5 15 * * *", async () => { exec("sh /home/script/script.sh", (error, stdout, stderr) => { if (error) { console.error( `Gagal menjalankan script antrisimatupang: ${error.message}` ); return; } if (stderr) { console.error(`Stderr antrisimatupang: ${stderr}`); return; } console.log(`Output antrisimatupang : ${stdout}`); }); exec("sh /home/script/script2.sh", (error, stdout, stderr) => { if (error) { console.error( `Gagal menjalankan script antributikemas: ${error.message}` ); return; } if (stderr) { console.error(`Stderr antributikemas : ${stderr}`); return; } console.log(`Output antributikemas : ${stdout}`); }); }, { timezone: "Asia/Jakarta", } ); cron.schedule( "14-19 7 * * *", async () => { exec("sh /home/script/script3.sh", (error, stdout, stderr) => { if (error) { console.error(`Gagal menjalankan script antribgr1: ${error.message}`); return; } if (stderr) { console.error(`Stderr antribgr1: ${stderr}`); return; } console.log(`Output antribgr1 : ${stdout}`); }); }, { timezone: "Asia/Jakarta", } ); app.use((req, res) => { res.json("What are you looking for?!"); }); app.listen(port, () => { console.log(`scheduler app listening on port ${port}`); });