server: stats endpoint (#468)

fixes #389
This commit is contained in:
C Cirello
2017-01-03 21:39:29 +01:00
committed by GitHub
parent 90092d2e8f
commit c48bd95fa6
6 changed files with 65 additions and 0 deletions

46
api/runner/stats.go Normal file
View File

@@ -0,0 +1,46 @@
package runner
import "sync"
type stats struct {
mu sync.Mutex
queue uint64
running uint64
complete uint64
}
type Stats struct {
Queue uint64
Running uint64
Complete uint64
}
func (s *stats) Enqueue() {
s.mu.Lock()
s.queue++
s.mu.Unlock()
}
func (s *stats) Start() {
s.mu.Lock()
s.queue--
s.running++
s.mu.Unlock()
}
func (s *stats) Complete() {
s.mu.Lock()
s.running--
s.complete++
s.mu.Unlock()
}
func (s *stats) Stats() Stats {
var stats Stats
s.mu.Lock()
stats.Running = s.running
stats.Complete = s.complete
stats.Queue = s.queue
s.mu.Unlock()
return stats
}