mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-16 12:53:42 +00:00
chore(poller): add metric to track the worker number
Add metric to track multiple task.
This commit is contained in:
1 parent
d1114da299
commit
abdb547b1b
3 files changed
+68
-32
No files matched your search
@@ -0,0 +1,33 @@
|
||||
package poller
|
||||
|
||||
import "sync/atomic"
|
||||
|
||||
// Metric interface
|
||||
type Metric interface {
|
||||
IncBusyWorker() uint64
|
||||
DecBusyWorker() uint64
|
||||
BusyWorkers() uint64
|
||||
}
|
||||
|
||||
var _ Metric = (*metric)(nil)
|
||||
|
||||
type metric struct {
|
||||
busyWorkers uint64
|
||||
}
|
||||
|
||||
// NewMetric for default metric structure
|
||||
func NewMetric() Metric {
|
||||
return &metric{}
|
||||
}
|
||||
|
||||
func (m *metric) IncBusyWorker() uint64 {
|
||||
return atomic.AddUint64(&m.busyWorkers, 1)
|
||||
}
|
||||
|
||||
func (m *metric) DecBusyWorker() uint64 {
|
||||
return atomic.AddUint64(&m.busyWorkers, ^uint64(0))
|
||||
}
|
||||
|
||||
func (m *metric) BusyWorkers() uint64 {
|
||||
return atomic.LoadUint64(&m.busyWorkers)
|
||||
}
|
||||
Reference in new issue
Block a user