mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-20 14:48:30 +02:00
add cron inflight metric
This commit is contained in:
parent
96246b93aa
commit
25eee166c4
@ -19,9 +19,17 @@ import (
|
|||||||
"code.gitea.io/gitea/modules/process"
|
"code.gitea.io/gitea/modules/process"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/translation"
|
"code.gitea.io/gitea/modules/translation"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
cronInflight = promauto.NewGauge(prometheus.GaugeOpts{
|
||||||
|
Namespace: "gitea",
|
||||||
|
Subsystem: "cron",
|
||||||
|
Name: "active_tasks",
|
||||||
|
Help: "Number of running cron tasks",
|
||||||
|
})
|
||||||
lock = sync.Mutex{}
|
lock = sync.Mutex{}
|
||||||
started = false
|
started = false
|
||||||
tasks = []*Task{}
|
tasks = []*Task{}
|
||||||
@ -86,6 +94,8 @@ func (t *Task) RunWithUser(doer *user_model.User, config Config) {
|
|||||||
taskStatusTable.Stop(t.Name)
|
taskStatusTable.Stop(t.Name)
|
||||||
}()
|
}()
|
||||||
graceful.GetManager().RunWithShutdownContext(func(baseCtx context.Context) {
|
graceful.GetManager().RunWithShutdownContext(func(baseCtx context.Context) {
|
||||||
|
cronInflight.Inc()
|
||||||
|
defer cronInflight.Dec()
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
// Recover a panic within the execution of the task.
|
// Recover a panic within the execution of the task.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user