mirror of https://github.com/go-co-op/gocron.git
add Singleton job rescheduled metric (#763)
This commit is contained in:
parent
3b2dcd869b
commit
68dba115b2
12
executor.go
12
executor.go
|
|
@ -196,7 +196,7 @@ func (e *executor) start() {
|
||||||
default:
|
default:
|
||||||
// runner is busy, reschedule the work for later
|
// runner is busy, reschedule the work for later
|
||||||
// which means we just skip it here and do nothing
|
// which means we just skip it here and do nothing
|
||||||
// TODO when metrics are added, this should increment a rescheduled metric
|
e.incrementJobCounter(*j, SingletonRescheduled)
|
||||||
e.sendOutForRescheduling(&jIn)
|
e.sendOutForRescheduling(&jIn)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -397,9 +397,7 @@ func (e *executor) runJob(j internalJob, jIn jobIn) {
|
||||||
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
err := e.callJobWithRecover(j)
|
err := e.callJobWithRecover(j)
|
||||||
if e.monitor != nil {
|
e.recordJobTiming(startTime, time.Now(), j)
|
||||||
e.monitor.RecordJobTiming(startTime, time.Now(), j.id, j.name, j.tags)
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = callJobFuncWithParams(j.afterJobRunsWithError, j.id, j.name, err)
|
_ = callJobFuncWithParams(j.afterJobRunsWithError, j.id, j.name, err)
|
||||||
e.incrementJobCounter(j, Fail)
|
e.incrementJobCounter(j, Fail)
|
||||||
|
|
@ -422,6 +420,12 @@ func (e *executor) callJobWithRecover(j internalJob) (err error) {
|
||||||
return callJobFuncWithParams(j.function, j.parameters...)
|
return callJobFuncWithParams(j.function, j.parameters...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *executor) recordJobTiming(start time.Time, end time.Time, j internalJob) {
|
||||||
|
if e.monitor != nil {
|
||||||
|
e.monitor.RecordJobTiming(start, end, j.id, j.name, j.tags)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (e *executor) incrementJobCounter(j internalJob, status JobStatus) {
|
func (e *executor) incrementJobCounter(j internalJob, status JobStatus) {
|
||||||
if e.monitor != nil {
|
if e.monitor != nil {
|
||||||
e.monitor.IncrementJob(j.id, j.name, j.tags, status)
|
e.monitor.IncrementJob(j.id, j.name, j.tags, status)
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ const (
|
||||||
Fail JobStatus = "fail"
|
Fail JobStatus = "fail"
|
||||||
Success JobStatus = "success"
|
Success JobStatus = "success"
|
||||||
Skip JobStatus = "skip"
|
Skip JobStatus = "skip"
|
||||||
|
SingletonRescheduled JobStatus = "singleton_rescheduled"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Monitor represents the interface to collect jobs metrics.
|
// Monitor represents the interface to collect jobs metrics.
|
||||||
|
|
|
||||||
|
|
@ -311,7 +311,7 @@ func (s *scheduler) selectRemoveJob(id uuid.UUID) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Jobs coming back from the executor to the scheduler that
|
// Jobs coming back from the executor to the scheduler that
|
||||||
// need to evaluated for rescheduling.
|
// need to be evaluated for rescheduling.
|
||||||
func (s *scheduler) selectExecJobsOutForRescheduling(id uuid.UUID) {
|
func (s *scheduler) selectExecJobsOutForRescheduling(id uuid.UUID) {
|
||||||
select {
|
select {
|
||||||
case <-s.shutdownCtx.Done():
|
case <-s.shutdownCtx.Done():
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue