MCPcopy Create free account
hub / github.com/DoNewsCode/core / WithMetrics

Function WithMetrics

cron/options.go:35–50  ·  view source on GitHub ↗

WithMetrics returns a new JobDescriptor that will report metrics.

(metrics *CronJobMetrics)

Source from the content-addressed store, hash-verified

33
34// WithMetrics returns a new JobDescriptor that will report metrics.
35func WithMetrics(metrics *CronJobMetrics) JobOption {
36 return func(descriptor *JobDescriptor) {
37 innerRun := descriptor.Run
38 descriptor.Run = func(ctx context.Context) error {
39 start := time.Now()
40 m := metrics.Job(descriptor.Name).Schedule(descriptor.RawSpec)
41 defer m.Observe(time.Since(start))
42 err := innerRun(ctx)
43 if err != nil {
44 m.Fail()
45 return err
46 }
47 return nil
48 }
49 }
50}
51
52// WithLogging returns a new Universal job that will log.
53func WithLogging(logger log.Logger) JobOption {

Callers 2

ProvideCronMethod · 0.92
TestJobOptionFunction · 0.85

Calls 4

ScheduleMethod · 0.80
JobMethod · 0.80
FailMethod · 0.80
ObserveMethod · 0.45

Tested by 2

ProvideCronMethod · 0.74
TestJobOptionFunction · 0.68