Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix : do not log cancellation errors in worker jobs #6540

Merged
merged 2 commits into from
Feb 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions admin/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package worker

import (
"context"
"errors"
"fmt"
"net/http"
"time"
Expand Down Expand Up @@ -107,7 +108,7 @@ func (w *Worker) RunJob(ctx context.Context, name string) error {
func (w *Worker) schedule(ctx context.Context, name string, fn func(context.Context) error, every time.Duration) error {
for {
err := w.runJob(ctx, name, fn)
if err != nil {
if err != nil && !errors.Is(err, context.Canceled) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about line 156?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is getting logged twice so I removed that log and added handling somewhere else as well.

w.logger.Error("Failed to run the job", zap.String("job_name", name), zap.Error(err))
}
select {
Expand All @@ -133,7 +134,7 @@ func (w *Worker) scheduleCron(ctx context.Context, name string, fn func(context.
return nil
case <-time.After(waitDuration):
err := w.runJob(ctx, name, fn)
if err != nil {
if err != nil && !errors.Is(err, context.Canceled) {
w.logger.Error("Failed to run the cronjob", zap.String("cronjob_name", name), zap.Error(err))
}
}
Expand All @@ -152,7 +153,6 @@ func (w *Worker) runJob(ctx context.Context, name string, fn func(context.Contex
err := fn(ctx)
jobLatencyHistogram.Record(ctx, time.Since(start).Milliseconds(), metric.WithAttributes(attribute.String("name", name), attribute.Bool("failed", err != nil)))
if err != nil {
w.logger.Error("job failed", zap.String("name", name), zap.Error(err), zap.Duration("duration", time.Since(start)), observability.ZapCtx(ctx))
return err
}
w.logger.Info("job completed", zap.String("name", name), zap.Duration("duration", time.Since(start)), observability.ZapCtx(ctx))
Expand Down
Loading