generated from rizalgowandy/library-template-go
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
alerter.go
46 lines (40 loc) · 865 Bytes
/
alerter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package cronx
import (
"context"
"fmt"
"time"
"github.com/rizalgowandy/gdk/pkg/errorx/v2"
"github.com/rizalgowandy/gdk/pkg/logx"
)
type AlerterItf interface {
NotifyHighLatency(
ctx context.Context,
job *Job,
prev, next time.Time,
latency, maxLatency time.Duration,
)
}
func NewAlerter() *Alerter {
return &Alerter{}
}
type Alerter struct{}
func (a *Alerter) NotifyHighLatency(
ctx context.Context,
job *Job,
prev, next time.Time,
latency, maxLatency time.Duration,
) {
logx.WRN(
ctx,
errorx.E(
"current run has not finished before a new run for next schedule is started",
errorx.Fields{
"prev_schedule": prev.String(),
"next_schedule": next.String(),
"current_latency": latency.String(),
"max_latency": maxLatency.String(),
},
),
fmt.Sprintf("Operation cron %s has high latency", job.Name),
)
}