2023-02-28 13:44:46 +03:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2022-11-11 10:00:38 +03:00
|
|
|
package poller
|
|
|
|
|
|
|
|
import "sync/atomic"
|
|
|
|
|
|
|
|
// Metric interface
|
|
|
|
type Metric interface {
|
2022-11-23 11:58:26 +03:00
|
|
|
IncBusyWorker() int64
|
|
|
|
DecBusyWorker() int64
|
|
|
|
BusyWorkers() int64
|
2022-11-11 10:00:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ Metric = (*metric)(nil)
|
|
|
|
|
|
|
|
type metric struct {
|
2022-11-23 11:58:26 +03:00
|
|
|
busyWorkers int64
|
2022-11-11 10:00:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewMetric for default metric structure
|
|
|
|
func NewMetric() Metric {
|
|
|
|
return &metric{}
|
|
|
|
}
|
|
|
|
|
2022-11-23 11:58:26 +03:00
|
|
|
func (m *metric) IncBusyWorker() int64 {
|
|
|
|
return atomic.AddInt64(&m.busyWorkers, 1)
|
2022-11-11 10:00:38 +03:00
|
|
|
}
|
|
|
|
|
2022-11-23 11:58:26 +03:00
|
|
|
func (m *metric) DecBusyWorker() int64 {
|
|
|
|
return atomic.AddInt64(&m.busyWorkers, -1)
|
2022-11-11 10:00:38 +03:00
|
|
|
}
|
|
|
|
|
2022-11-23 11:58:26 +03:00
|
|
|
func (m *metric) BusyWorkers() int64 {
|
|
|
|
return atomic.LoadInt64(&m.busyWorkers)
|
2022-11-11 10:00:38 +03:00
|
|
|
}
|