0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-07-18 13:02:54 +02:00

add cron inflight metric

This commit is contained in:
TheFox0x7 2025-07-08 23:22:00 +02:00
parent 96246b93aa
commit 25eee166c4
No known key found for this signature in database
GPG Key ID: 6CA33903484AF7C2

View File

@ -19,9 +19,17 @@ import (
"code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/translation"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
var (
cronInflight = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gitea",
Subsystem: "cron",
Name: "active_tasks",
Help: "Number of running cron tasks",
})
lock = sync.Mutex{}
started = false
tasks = []*Task{}
@ -86,6 +94,8 @@ func (t *Task) RunWithUser(doer *user_model.User, config Config) {
taskStatusTable.Stop(t.Name)
}()
graceful.GetManager().RunWithShutdownContext(func(baseCtx context.Context) {
cronInflight.Inc()
defer cronInflight.Dec()
defer func() {
if err := recover(); err != nil {
// Recover a panic within the execution of the task.