Skip to content

Commit

Permalink
Rename it
Browse files Browse the repository at this point in the history
  • Loading branch information
gorodet-sky committed Jan 10, 2024
1 parent 625bf25 commit 5ddb30d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var (
ErrWithNameEmpty = fmt.Errorf("gocron: WithName: name must not be empty")
ErrWithStartDateTimePast = fmt.Errorf("gocron: WithStartDateTime: start must not be in the past")
ErrWithStopTimeoutZeroOrNegative = fmt.Errorf("gocron: WithStopTimeout: timeout must be greater than 0")
ErrWithMonitorerNil = fmt.Errorf("gocron: WithMonitorer: monitorer must not be nil")
ErrWithMonitorNil = fmt.Errorf("gocron: WithMonitor: monitor must not be nil")
)

// internal errors
Expand Down
14 changes: 7 additions & 7 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type executor struct {
limitMode *limitModeConfig
elector Elector
locker Locker
monitorer Monitorer
monitor Monitor
}

type jobIn struct {
Expand Down Expand Up @@ -353,18 +353,18 @@ func (e *executor) runJob(j internalJob, shouldSendOut bool) {

startTime := time.Now()
err := callJobFuncWithParams(j.function, j.parameters...)
if e.monitorer != nil {
e.monitorer.WriteTiming(startTime, time.Now(), j.id, j.name, j.tags)
if e.monitor != nil {
e.monitor.WriteTiming(startTime, time.Now(), j.id, j.name, j.tags)
}
if err != nil {
_ = callJobFuncWithParams(j.afterJobRunsWithError, j.id, j.name, err)
if e.monitorer != nil {
e.monitorer.Inc(j.id, j.name, j.tags, Fail)
if e.monitor != nil {
e.monitor.Inc(j.id, j.name, j.tags, Fail)
}
} else {
_ = callJobFuncWithParams(j.afterJobRuns, j.id, j.name)
if e.monitorer != nil {
e.monitorer.Inc(j.id, j.name, j.tags, Success)
if e.monitor != nil {
e.monitor.Inc(j.id, j.name, j.tags, Success)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const (
Success JobStatus = "success"
)

// Monitorer represents the interface to collect jobs metrics.
type Monitorer interface {
// Monitor represents the interface to collect jobs metrics.
type Monitor interface {
Inc(id uuid.UUID, name string, tags []string, status JobStatus)
WriteTiming(startTime, endTime time.Time, id uuid.UUID, name string, tags []string)
}
10 changes: 5 additions & 5 deletions scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,13 +775,13 @@ func WithStopTimeout(timeout time.Duration) SchedulerOption {
}
}

// WithMonitorer sets the metrics provider to be used by the Scheduler.
func WithMonitorer(monitorer Monitorer) SchedulerOption {
// WithMonitor sets the metrics provider to be used by the Scheduler.
func WithMonitor(monitor Monitor) SchedulerOption {
return func(s *scheduler) error {
if monitorer == nil {
return ErrWithMonitorerNil
if monitor == nil {
return ErrWithMonitorNil
}
s.exec.monitorer = monitorer
s.exec.monitor = monitor
return nil
}
}
6 changes: 3 additions & 3 deletions scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,8 +910,8 @@ func TestScheduler_WithOptionsErrors(t *testing.T) {
},
{
"WithMonitorer nil",
WithMonitorer(nil),
ErrWithMonitorerNil,
WithMonitor(nil),
ErrWithMonitorNil,
},
}

Expand Down Expand Up @@ -1721,7 +1721,7 @@ func TestScheduler_WithMonitorer(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
ch := make(chan struct{}, 20)
testMonitorer := newTestMonitorer()
s, err := NewScheduler(WithMonitorer(testMonitorer))
s, err := NewScheduler(WithMonitor(testMonitorer))
require.NoError(t, err)

opt := []JobOption{
Expand Down

0 comments on commit 5ddb30d

Please sign in to comment.