Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove collisions on PrepareRun stage #546

Merged
merged 3 commits into from
Jun 8, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions api/tasks/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,36 @@ func (p *taskPool) run() {
case task := <-p.register:
p.queue = append(p.queue, task)
log.Debug(task)
task.log("Task " + strconv.Itoa(task.task.ID) + " added to queue")
msg := "Task " + strconv.Itoa(task.task.ID) + " added to queue"
task.log(msg)
log.Info(msg)
case <-ticker.C:
if len(p.queue) == 0 {
continue
} else if t := p.queue[0]; t.task.Status != taskFailStatus && p.blocks(t) {
p.queue = append(p.queue[1:], t)
continue
}

if t := p.queue[0]; t.task.Status != taskFailStatus {
log.Info("Set resourse locker with task " + strconv.Itoa(t.task.ID))
resourceLocker <- &resourceLock{lock: true, holder: t}
if !t.prepared {
go t.prepareRun()
continue
}
go t.run()
//get task from top of queue
t := p.queue[0]
if t.task.Status == taskFailStatus {
//delete failed task from queue
p.queue = p.queue[1:]
log.Info("Task " + strconv.Itoa(t.task.ID) + " removed from queue")
continue
}
if p.blocks(t) {
//move blocked task to end of queue
p.queue = append(p.queue[1:], t)
continue
}
log.Info("Set resourse locker with task " + strconv.Itoa(t.task.ID))
resourceLocker <- &resourceLock{lock: true, holder: t}
if !t.prepared {
go t.prepareRun()
continue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we continue here and not just directly run the task after we prepare it? The next tick will just run the task anyway right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, without continue it trying to run a task at the same tick with prepare because it checking the lock before this branch

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have had a coffee before reviewing this pr 😆
approved

}
go t.run()
p.queue = p.queue[1:]
log.Info("Task " + strconv.Itoa(t.task.ID) + " removed from queue")
}
}
}
Expand Down