Skip to content

Commit

Permalink
feat(scheduler): add error logging on run interruption
Browse files Browse the repository at this point in the history
  • Loading branch information
karol-kokoszka committed Mar 26, 2024
1 parent 377610a commit 7698860
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions pkg/scheduler/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package scheduler
import (
"context"
"time"

"github.com/scylladb/go-log"
)

// Listener specifies pluggable hooks for scheduler events.
Expand Down Expand Up @@ -74,3 +76,26 @@ func (l nopListener[K]) OnSleep(context.Context, K, time.Duration) {
func NopListener[K comparable]() Listener[K] {
return nopListener[K]{}
}

type errorLogListener[K comparable] struct {
nopListener[K]
logger log.Logger
}

func (l errorLogListener[K]) OnRunError(ctx *RunContext[K], err error) {
l.logger.Error(ctx, "OnRunError", "key", ctx.Key, "retry", ctx.Retry, "error", err)
}

func (l errorLogListener[K]) OnRunWindowEnd(ctx *RunContext[K]) {
l.logger.Info(ctx, "OnRunWindowEnd", "key", ctx.Key, "retry", ctx.Retry)
}

func (l errorLogListener[K]) OnRunStop(ctx *RunContext[K]) {
l.logger.Info(ctx, "OnRunStop", "key", ctx.Key, "retry", ctx.Retry)
}

func ErrorLogListener[K comparable](logger log.Logger) Listener[K] {

Check failure on line 97 in pkg/scheduler/listener.go

View workflow job for this annotation

GitHub Actions / Various checks

exported: exported function ErrorLogListener should have comment or be unexported (revive)
return errorLogListener[K]{
logger: logger,
}
}
2 changes: 1 addition & 1 deletion pkg/service/scheduler/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type schedulerListener struct {

func newSchedulerListener(find func(key Key) (taskInfo, bool), logger log.Logger) schedulerListener {
return schedulerListener{
Listener: scheduler.NopListener[Key](),
Listener: scheduler.ErrorLogListener[Key](logger),
find: find,
logger: logger,
}
Expand Down

0 comments on commit 7698860

Please sign in to comment.