-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (34 loc) · 1.48 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const schedule = require('node-schedule');
const { spawn } = require("child_process");
const { sendWebhook } = require("./utilities/webhook");
const path = require('path');
require('dotenv').config({ path: path.join(__dirname, '.env') });
//collect rule times for cron job
let rule = `${process.env.RULE_SECOND} ${process.env.RULE_MINUTE} ${process.env.RULE_HOUR} ${process.env.RULE_DATE} ${process.env.RULE_MONTH} ${process.env.RULE_WEEK_DAY}`;
//start cron
const job = schedule.scheduleJob(rule, function(){
//command to service restart wings
let wings = spawn('service', ['wings', 'restart']);
//if the command runs correctly
wings.stdout.on('data', (data) => {
sendWebhook(`${process.env.TITLE} Succesfully Ran`, process.env.DISCORD_URL, false);
});
//if the command returns errors
wings.stderr.on('data', (data) => {
sendWebhook(`${process.env.TITLE} Failed To Run`, process.env.DISCORD_URL, true);
});
//if the command window fails to start
wings.on('error', function(err){
sendWebhook(`${process.env.TITLE} Failed To Run`, process.env.DISCORD_URL, true);
});
wings.on('exit', (code) => {
//if the command runs correctly
if(code == 0){
sendWebhook(`${process.env.TITLE} Succesfully Ran`, process.env.DISCORD_URL, false);
}else{
sendWebhook(`${process.env.TITLE} Failed To Run`, process.env.DISCORD_URL, true);
}
});
//close window
wings.stdin.end();
});