Monitor: IncrementJob in case of skipped job run (#715)

Co-authored-by: John Roesler <johnrroesler@gmail.com>
This commit is contained in:
Giridharan Ramasamy 2024-04-29 23:59:11 +05:30 committed by GitHub
parent a59b6a928a
commit cde2513062
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 6 deletions

View File

@ -333,12 +333,14 @@ func (e *executor) runJob(j internalJob, jIn jobIn) {
if e.elector != nil {
if err := e.elector.IsLeader(j.ctx); err != nil {
e.sendOutForRescheduling(&jIn)
e.incrementJobCounter(j, Skip)
return
}
} else if j.locker != nil {
lock, err := j.locker.Lock(j.ctx, j.name)
if err != nil {
e.sendOutForRescheduling(&jIn)
e.incrementJobCounter(j, Skip)
return
}
defer func() { _ = lock.Unlock(j.ctx) }()
@ -346,6 +348,7 @@ func (e *executor) runJob(j internalJob, jIn jobIn) {
lock, err := e.locker.Lock(j.ctx, j.name)
if err != nil {
e.sendOutForRescheduling(&jIn)
e.incrementJobCounter(j, Skip)
return
}
defer func() { _ = lock.Unlock(j.ctx) }()
@ -365,14 +368,16 @@ func (e *executor) runJob(j internalJob, jIn jobIn) {
}
if err != nil {
_ = callJobFuncWithParams(j.afterJobRunsWithError, j.id, j.name, err)
if e.monitor != nil {
e.monitor.IncrementJob(j.id, j.name, j.tags, Fail)
}
e.incrementJobCounter(j, Fail)
} else {
_ = callJobFuncWithParams(j.afterJobRuns, j.id, j.name)
if e.monitor != nil {
e.monitor.IncrementJob(j.id, j.name, j.tags, Success)
}
e.incrementJobCounter(j, Success)
}
}
func (e *executor) incrementJobCounter(j internalJob, status JobStatus) {
if e.monitor != nil {
e.monitor.IncrementJob(j.id, j.name, j.tags, status)
}
}

View File

@ -13,6 +13,7 @@ type JobStatus string
const (
Fail JobStatus = "fail"
Success JobStatus = "success"
Skip JobStatus = "skip"
)
// Monitor represents the interface to collect jobs metrics.