initial implementation #1
@ -29,7 +29,7 @@ package models
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
type PendingInformation struct {
|
type JobInformation struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
Data string `json:"data"`
|
Data string `json:"data"`
|
||||||
Labels map[string]string `json:"labels"`
|
Labels map[string]string `json:"labels"`
|
||||||
@ -48,9 +48,9 @@ type Stats struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type QueueInfo struct {
|
type QueueInfo struct {
|
||||||
Pending []PendingInformation `json:"pending,omitempty"`
|
Pending []JobInformation `json:"pending,omitempty"`
|
||||||
WaitingOnDeps string `json:"-"` // dont need those
|
WaitingOnDeps string `json:"-"` // dont need those
|
||||||
Running int `json:"running,omitempty"`
|
Running []JobInformation `json:"running,omitempty"`
|
||||||
Stats Stats `json:"stats"`
|
Stats Stats `json:"stats"`
|
||||||
Paused bool `json:"paused"`
|
Paused bool `json:"paused"`
|
||||||
}
|
}
|
||||||
|
@ -64,14 +64,27 @@ func CheckPending(cfg *config.Config) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CheckRunning(cfg *config.Config) (bool, error) {
|
func CheckRunning(cfg *config.Config) (bool, error) {
|
||||||
|
expectedKV := strings.Split(cfg.WoodpeckerLabelSelector, "=")
|
||||||
queueInfo := new(models.QueueInfo)
|
queueInfo := new(models.QueueInfo)
|
||||||
err := QueueInfo(cfg, queueInfo)
|
err := QueueInfo(cfg, queueInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errors.New(fmt.Sprintf("Error from QueueInfo: %s", err.Error()))
|
return false, errors.New(fmt.Sprintf("Error from QueueInfo: %s", err.Error()))
|
||||||
}
|
}
|
||||||
// TODO: create and parse running object. there may be jobs that are not for us
|
|
||||||
if queueInfo.Stats.RunningCount > 0 {
|
if queueInfo.Stats.RunningCount > 0 {
|
||||||
|
for _, runningJobs := range queueInfo.Running {
|
||||||
|
val, exists := runningJobs.Labels[expectedKV[0]]
|
||||||
|
if exists && val == expectedKV[1] {
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"Caller": "CheckRunning",
|
||||||
|
}).Info("Found running job for us")
|
||||||
return true, nil
|
return true, nil
|
||||||
|
} else {
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"Caller": "CheckRunning",
|
||||||
|
}).Info("No running job for us")
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user