#2 match owned nodes with pending/running tasks
All checks were successful
Pipeline was successful
All checks were successful
Pipeline was successful
This commit is contained in:
parent
98d48f006f
commit
bbdcedf6de
@ -51,7 +51,7 @@ func main() {
|
||||
log.WithFields(log.Fields{
|
||||
"Caller": "Main",
|
||||
}).Infof("Currently owning %d Agents", len(ownedNodes))
|
||||
if pendingTasks {
|
||||
if pendingTasks < len(ownedNodes) {
|
||||
server, err := hetzner.CreateNewAgent(cfg)
|
||||
if err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
@ -86,7 +86,7 @@ func main() {
|
||||
"Caller": "Main",
|
||||
}).Fatal(fmt.Sprintf("Error checking woodpecker queue: %s", err.Error()))
|
||||
}
|
||||
if runningTasks {
|
||||
if runningTasks <= len(ownedNodes) {
|
||||
log.WithFields(log.Fields{
|
||||
"Caller": "Main",
|
||||
}).Info("Still found running tasks. No agent to be removed")
|
||||
|
@ -35,56 +35,48 @@ func QueueInfo(cfg *config.Config, target interface{}) error {
|
||||
return json.NewDecoder(resp.Body).Decode(target)
|
||||
}
|
||||
|
||||
func CheckPending(cfg *config.Config) (bool, error) {
|
||||
func CheckPending(cfg *config.Config) (int, error) {
|
||||
expectedKV := strings.Split(cfg.WoodpeckerLabelSelector, "=")
|
||||
queueInfo := new(models.QueueInfo)
|
||||
err := QueueInfo(cfg, queueInfo)
|
||||
if err != nil {
|
||||
return false, errors.New(fmt.Sprintf("Error from QueueInfo: %s", err.Error()))
|
||||
return 0, errors.New(fmt.Sprintf("Error from QueueInfo: %s", err.Error()))
|
||||
}
|
||||
count := 0
|
||||
if queueInfo.Stats.PendingCount > 0 {
|
||||
if queueInfo.Pending != nil {
|
||||
for _, pendingJobs := range queueInfo.Pending {
|
||||
val, exists := pendingJobs.Labels[expectedKV[0]]
|
||||
if exists && val == expectedKV[1] {
|
||||
count++
|
||||
log.WithFields(log.Fields{
|
||||
"Caller": "CheckPending",
|
||||
}).Info("Found pending job for us")
|
||||
return true, nil
|
||||
} else {
|
||||
log.WithFields(log.Fields{
|
||||
"Caller": "CheckPending",
|
||||
}).Info("No Jobs for us in Queue")
|
||||
return false, nil
|
||||
}).Debugf("Currently serving %d Jobs", count)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func CheckRunning(cfg *config.Config) (bool, error) {
|
||||
func CheckRunning(cfg *config.Config) (int, error) {
|
||||
expectedKV := strings.Split(cfg.WoodpeckerLabelSelector, "=")
|
||||
queueInfo := new(models.QueueInfo)
|
||||
err := QueueInfo(cfg, queueInfo)
|
||||
if err != nil {
|
||||
return false, errors.New(fmt.Sprintf("Error from QueueInfo: %s", err.Error()))
|
||||
return 0, errors.New(fmt.Sprintf("Error from QueueInfo: %s", err.Error()))
|
||||
}
|
||||
count := 0
|
||||
if queueInfo.Stats.RunningCount > 0 {
|
||||
for _, runningJobs := range queueInfo.Running {
|
||||
val, exists := runningJobs.Labels[expectedKV[0]]
|
||||
if exists && val == expectedKV[1] {
|
||||
count++
|
||||
log.WithFields(log.Fields{
|
||||
"Caller": "CheckRunning",
|
||||
}).Info("Found running job for us")
|
||||
return true, nil
|
||||
} else {
|
||||
log.WithFields(log.Fields{
|
||||
"Caller": "CheckRunning",
|
||||
}).Info("No running job for us")
|
||||
return false, nil
|
||||
}).Debugf("Currently serving %d Jobs", count)
|
||||
}
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
return count, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user