mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2024-11-27 08:18:53 +03:00
552dbcdda9
Add copyright header Co-authored-by: sillyguodong <gedong_1994@163.com> Reviewed-on: https://gitea.com/gitea/act_runner/pulls/29 Reviewed-by: Jason Song <i@wolfogre.com> Reviewed-by: Zettat123 <zettat123@noreply.gitea.io> Co-authored-by: sillyguodong <sillyguodong@noreply.gitea.io> Co-committed-by: sillyguodong <sillyguodong@noreply.gitea.io>
36 lines
663 B
Go
36 lines
663 B
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package poller
|
|
|
|
import "sync/atomic"
|
|
|
|
// Metric interface
|
|
type Metric interface {
|
|
IncBusyWorker() int64
|
|
DecBusyWorker() int64
|
|
BusyWorkers() int64
|
|
}
|
|
|
|
var _ Metric = (*metric)(nil)
|
|
|
|
type metric struct {
|
|
busyWorkers int64
|
|
}
|
|
|
|
// NewMetric for default metric structure
|
|
func NewMetric() Metric {
|
|
return &metric{}
|
|
}
|
|
|
|
func (m *metric) IncBusyWorker() int64 {
|
|
return atomic.AddInt64(&m.busyWorkers, 1)
|
|
}
|
|
|
|
func (m *metric) DecBusyWorker() int64 {
|
|
return atomic.AddInt64(&m.busyWorkers, -1)
|
|
}
|
|
|
|
func (m *metric) BusyWorkers() int64 {
|
|
return atomic.LoadInt64(&m.busyWorkers)
|
|
}
|