handle empty queue
All checks were successful
Pipeline was successful

This commit is contained in:
Tobias Trabelsi 2023-11-08 20:42:20 +01:00
parent 089df0ff7f
commit bbaa89d4c2
Signed by: lerentis
GPG Key ID: FF0C2839718CAF2E

View File

@ -86,23 +86,29 @@ func main() {
"Caller": "Main",
}).Fatal(fmt.Sprintf("Error checking woodpecker queue: %s", err.Error()))
}
if runningTasks <= len(ownedNodes) {
if runningTasks <= len(ownedNodes) && runningTasks != 0 {
log.WithFields(log.Fields{
"Caller": "Main",
}).Info("Still found running tasks. No agent to be removed")
} else {
log.WithFields(log.Fields{
"Caller": "Main",
}).Info("No tasks running. Will remove agents")
for _, server := range ownedNodes {
hetzner.DecomNode(cfg, &server)
agentId, err := woodpecker.GetAgentIdByName(cfg, server.Name)
if err != nil {
log.WithFields(log.Fields{
"Caller": "Main",
}).Warnf("Could not find agent %s in woodpecker. Assuming it was never added", server.Name)
} else {
woodpecker.DecomAgent(cfg, agentId)
if len(ownedNodes) == 0 {
log.WithFields(log.Fields{
"Caller": "Main",
}).Infof("Nothing running and not owning any nodes. Recheck in %d", cfg.CheckInterval)
} else {
log.WithFields(log.Fields{
"Caller": "Main",
}).Info("No tasks running. Will remove agents")
for _, server := range ownedNodes {
hetzner.DecomNode(cfg, &server)
agentId, err := woodpecker.GetAgentIdByName(cfg, server.Name)
if err != nil {
log.WithFields(log.Fields{
"Caller": "Main",
}).Warnf("Could not find agent %s in woodpecker. Assuming it was never added", server.Name)
} else {
woodpecker.DecomAgent(cfg, agentId)
}
}
}
}