Skip to content

Commit

Permalink
add requested changes, add some logging
Browse files Browse the repository at this point in the history
  • Loading branch information
strangeman committed Jun 8, 2018
1 parent 087acb8 commit a817d2d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
19 changes: 10 additions & 9 deletions api/tasks/pool.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package tasks

import (
"fmt"
"strconv"
"time"

log "github.com/Sirupsen/logrus"
"github.com/ansible-semaphore/semaphore/util"
)

Expand Down Expand Up @@ -74,8 +75,9 @@ func (p *taskPool) run() {
for {
select {
case task := <-p.register:
fmt.Println(task)
p.queue = append(p.queue, task)
log.Debug(task)
task.log("Task " + strconv.Itoa(task.task.ID) + " added to queue")
case <-ticker.C:
if len(p.queue) == 0 {
continue
Expand All @@ -85,15 +87,14 @@ func (p *taskPool) run() {
}

if t := p.queue[0]; t.task.Status != taskFailStatus {
if t.prepared {
fmt.Println("Running a task.")
resourceLocker <- &resourceLock{lock: true, holder: t}
go t.run()
p.queue = p.queue[1:]
} else {
resourceLocker <- &resourceLock{lock: true, holder: t}
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()
p.queue = p.queue[1:]
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions api/tasks/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strings"
"time"

log "github.com/Sirupsen/logrus"
"github.com/ansible-semaphore/semaphore/db"
"github.com/ansible-semaphore/semaphore/util"
)
Expand Down Expand Up @@ -49,7 +50,8 @@ func (t *task) prepareRun() {
t.prepared = false

defer func() {
fmt.Println("Stopped preparing task")
log.Info("Stopped preparing task " + strconv.Itoa(t.task.ID))
log.Info("Release resourse locker with task " + strconv.Itoa(t.task.ID))
resourceLocker <- &resourceLock{lock: false, holder: t}

objType := taskTypeID
Expand Down Expand Up @@ -130,7 +132,8 @@ func (t *task) prepareRun() {

func (t *task) run() {
defer func() {
fmt.Println("Stopped running tasks")
log.Info("Stopped running task " + strconv.Itoa(t.task.ID))
log.Info("Release resourse locker with task " + strconv.Itoa(t.task.ID))
resourceLocker <- &resourceLock{lock: false, holder: t}

now := time.Now()
Expand Down

0 comments on commit a817d2d

Please sign in to comment.