mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
47 lines
610 B
Go
47 lines
610 B
Go
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
|
|
}
|