Just do git updates

This commit is contained in:
bingus_violet 2024-08-09 02:11:07 -05:00
parent e4cf4e88a4
commit 2c7166bd2b
2 changed files with 5 additions and 42 deletions

View file

@ -1,8 +1,6 @@
{ {
"autoUpdates": [ "dirs": [
{
}
], ],
"updateSpeedMinutes": 5 "updateSpeedMinutes": 5
} }

View file

@ -15,50 +15,15 @@ if (!fs.existsSync(confPath)) {
console.log("Done!") console.log("Done!")
} }
var runningPrograms = {
}
var iterations = 0
function updateLoop() { function updateLoop() {
iterations += 1
var config = JSON.parse(fs.readFileSync(confPath)) var config = JSON.parse(fs.readFileSync(confPath))
for (var i = 0; i < config.dirs.length; i++) {
for (var i = 0; i < config.autoUpdates.length; i++) { shell.exec(`cd ${config.dirs[i]} && git pull`)
var program = config.autoUpdates[i]
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(() => { setTimeout(() => {
if (iterations >= 5) {
iterations = 0
}
updateLoop() updateLoop()
}, config.updateSpeedMinutes * 60 * 1000 / 5); }, config.updateSpeedMinutes * 60 * 1000);
} }
updateLoop() updateLoop()