Ensure program is running if it closes early

This commit is contained in:
bingus_violet 2024-06-09 21:07:52 -05:00
parent 2d90dbedb8
commit e4cf4e88a4

View file

@ -19,27 +19,46 @@ var runningPrograms = {
}
var iterations = 0
function updateLoop() {
iterations += 1
var config = JSON.parse(fs.readFileSync(confPath))
for (var i = 0; i < config.autoUpdates.length; i++) {
var program = config.autoUpdates[i]
var pull = shell.exec(`cd ${program.dir} && git pull`)
if (!runningPrograms[program.name]) {
runningPrograms[program.name] = shell.exec(`cd ${program.dir} && ${program.startCommand}`, { async: true })
}
if (!pull.stdout.includes("Already up to date.")) {
if (runningPrograms[program.name]) {
runningPrograms[program.name].kill()
}
runningPrograms[program.name] = shell.exec(`cd ${program.dir} && ${program.startCommand}`, { async: true })
var runningProgram = runningPrograms[program.name]
function startProgram() {
return shell.exec(`cd ${program.dir} && ${program.startCommand}`, { async: true },
() => {
runningPrograms[program.name] = undefined
})
}
if (!runningProgram) {
runningPrograms[program.name] = startProgram()
}
if (iterations >= 5) {
var pull = shell.exec(`cd ${program.dir} && git pull`)
if (!pull.stdout.includes("Already up to date.")) {
if (runningProgram) {
runningProgram.kill()
runningPrograms[program.name] = startProgram()
}
}
}
}
setTimeout(() => {
if (iterations >= 5) {
iterations = 0
}
updateLoop()
}, config.updateSpeedMinutes * 60 * 1000);
}, config.updateSpeedMinutes * 60 * 1000 / 5);
}
updateLoop()