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

chore: simplified code to satisfy linter #223

Merged
merged 1 commit into from
Sep 29, 2023
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
33 changes: 18 additions & 15 deletions worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,21 +239,7 @@ func (w *Worker) WorkOne(ctx context.Context) (didWork bool) {

wf, ok := w.wm[j.Type]
if !ok {
w.mWorked.Add(ctx, 1, metric.WithAttributes(attrJobType.String(j.Type), attrSuccess.Bool(false)))

span.RecordError(fmt.Errorf("job with unknown type: %q", j.Type))
ll.Error("Got a job with unknown type")

errUnknownType := fmt.Errorf("worker[id=%s] unknown job type: %q", w.id, j.Type)
if err = j.Error(ctx, errUnknownType); err != nil {
span.RecordError(fmt.Errorf("failed to mark job as error: %w", err))
ll.Error("Got an error on setting an error to unknown job", adapter.Err(err))
}

for _, hook := range w.hooksUnknownJobType {
hook(ctx, j, errUnknownType)
}

w.handleUnknownJobType(ctx, j, span, ll)
return
}

Expand Down Expand Up @@ -294,6 +280,23 @@ func (w *Worker) WorkOne(ctx context.Context) (didWork bool) {
return
}

func (w *Worker) handleUnknownJobType(ctx context.Context, j *Job, span trace.Span, ll adapter.Logger) {
w.mWorked.Add(ctx, 1, metric.WithAttributes(attrJobType.String(j.Type), attrSuccess.Bool(false)))

span.RecordError(fmt.Errorf("job with unknown type: %q", j.Type))
ll.Error("Got a job with unknown type")

errUnknownType := fmt.Errorf("worker[id=%s] unknown job type: %q", w.id, j.Type)
if err := j.Error(ctx, errUnknownType); err != nil {
span.RecordError(fmt.Errorf("failed to mark job as error: %w", err))
ll.Error("Got an error on setting an error to unknown job", adapter.Err(err))
}

for _, hook := range w.hooksUnknownJobType {
hook(ctx, j, errUnknownType)
}
}

func (w *Worker) initMetrics() (err error) {
if w.mWorked, err = w.meter.Int64Counter(
"gue_worker_jobs_worked",
Expand Down