Skip to content

Commit d4d7412

Browse files
committed
Fix initial delay by triggering immediate first run in schedule
1 parent bd88683 commit d4d7412

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

index.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ class WindowsSystemMonitor {
5353
}
5454

5555
async function main() {
56-
console.log('Starting WhatsApp service...')
56+
console.log("Starting WhatsApp service...");
5757
const whatsAppService = new WhatsAppService();
5858
await whatsAppService.ready();
5959

60-
schedule.scheduleJob(config.schedule, () => {
60+
function monitorService() {
6161
WindowsSystemMonitor.checkPythonService((err, stdout, stderr) => {
6262
if (err) {
6363
console.error("Error:", err);
@@ -70,13 +70,21 @@ async function main() {
7070
}
7171

7272
if (!stdout.includes(config.serviceName)) {
73-
console.log('Service is not running');
74-
whatsAppService.sendMessage(config.chatId, config.serviceName + " is not running, please check!");
73+
console.log("Service is not running");
74+
whatsAppService.sendMessage(
75+
config.chatId,
76+
config.serviceName + " is not running, please check!"
77+
);
78+
console.log("Message sent to " + config.chatId);
7579
} else {
76-
console.log('Service is running');
80+
console.log("Service is running");
7781
}
7882
});
79-
});
83+
}
84+
85+
monitorService();
86+
87+
schedule.scheduleJob(config.schedule, monitorService);
8088
}
8189

8290
main();

0 commit comments

Comments
 (0)