Add job monitor interface to allow for collecting job metrics (#659)
* Add metrics each run of job * Fix lint * Fix test lint * Fix backwards job status * Add tags * Comment example * Rename it * Fix some names * Fix readme * update readme, examples, naming * fix unrelated test that was leaking scheduler * remove overzealous leak detection * rename interface methods --------- Co-authored-by: gorodet-sky <gorodetsky.dev@gmail.com>
This commit is contained in:
+11
@@ -23,6 +23,7 @@ type executor struct {
|
||||
limitMode *limitModeConfig
|
||||
elector Elector
|
||||
locker Locker
|
||||
monitor Monitor
|
||||
}
|
||||
|
||||
type jobIn struct {
|
||||
@@ -350,11 +351,21 @@ func (e *executor) runJob(j internalJob, shouldSendOut bool) {
|
||||
}
|
||||
}
|
||||
|
||||
startTime := time.Now()
|
||||
err := callJobFuncWithParams(j.function, j.parameters...)
|
||||
if e.monitor != nil {
|
||||
e.monitor.RecordJobTiming(startTime, time.Now(), j.id, j.name, j.tags)
|
||||
}
|
||||
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)
|
||||
}
|
||||
} else {
|
||||
_ = callJobFuncWithParams(j.afterJobRuns, j.id, j.name)
|
||||
if e.monitor != nil {
|
||||
e.monitor.IncrementJob(j.id, j.name, j.tags, Success)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user