mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-02-22 22:26:20 +00:00
Small refactor
This commit is contained in:
parent
788973d0d1
commit
e411893c62
1 changed files with 14 additions and 10 deletions
|
@ -192,15 +192,7 @@ func (q *fifo) process() {
|
||||||
q.Lock()
|
q.Lock()
|
||||||
defer q.Unlock()
|
defer q.Unlock()
|
||||||
|
|
||||||
// TODO(bradrydzewski) move this to a helper function
|
q.resubmitExpiredBuilds()
|
||||||
// push items to the front of the queue if the item expires.
|
|
||||||
for id, state := range q.running {
|
|
||||||
if time.Now().After(state.deadline) {
|
|
||||||
q.pending.PushFront(state.item)
|
|
||||||
delete(q.running, id)
|
|
||||||
close(state.done)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var next *list.Element
|
var next *list.Element
|
||||||
loop:
|
loop:
|
||||||
|
@ -209,6 +201,7 @@ loop:
|
||||||
task := e.Value.(*Task)
|
task := e.Value.(*Task)
|
||||||
logrus.Debugf("queue: trying to assign task: %v with deps %v", task.ID, task.Dependencies)
|
logrus.Debugf("queue: trying to assign task: %v with deps %v", task.ID, task.Dependencies)
|
||||||
if q.depsInQueue(task) {
|
if q.depsInQueue(task) {
|
||||||
|
logrus.Debugf("queue: skipping due to unmet dependencies %v", task.ID)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for w := range q.workers {
|
for w := range q.workers {
|
||||||
|
@ -230,12 +223,22 @@ loop:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (q *fifo) resubmitExpiredBuilds() {
|
||||||
|
for id, state := range q.running {
|
||||||
|
if time.Now().After(state.deadline) {
|
||||||
|
q.pending.PushFront(state.item)
|
||||||
|
delete(q.running, id)
|
||||||
|
close(state.done)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (q *fifo) depsInQueue(task *Task) bool {
|
func (q *fifo) depsInQueue(task *Task) bool {
|
||||||
var next *list.Element
|
var next *list.Element
|
||||||
for e := q.pending.Front(); e != nil; e = next {
|
for e := q.pending.Front(); e != nil; e = next {
|
||||||
next = e.Next()
|
next = e.Next()
|
||||||
possibleDep, ok := e.Value.(*Task)
|
possibleDep, ok := e.Value.(*Task)
|
||||||
logrus.Debugf("queue: in queue right now: %v", possibleDep.ID)
|
logrus.Debugf("queue: pending right now: %v", possibleDep.ID)
|
||||||
for _, dep := range task.Dependencies {
|
for _, dep := range task.Dependencies {
|
||||||
if ok && possibleDep.ID == dep {
|
if ok && possibleDep.ID == dep {
|
||||||
return true
|
return true
|
||||||
|
@ -243,6 +246,7 @@ func (q *fifo) depsInQueue(task *Task) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for possibleDepID := range q.running {
|
for possibleDepID := range q.running {
|
||||||
|
logrus.Debugf("queue: running right now: %v", possibleDepID)
|
||||||
for _, dep := range task.Dependencies {
|
for _, dep := range task.Dependencies {
|
||||||
if possibleDepID == dep {
|
if possibleDepID == dep {
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in a new issue