Skip to content

Commit

Permalink
Merge pull request #223 from vgarvardt/chore/simplify-code-for-linter
Browse files Browse the repository at this point in the history
chore: simplified code to satisfy linter
  • Loading branch information
vgarvardt authored Sep 29, 2023
2 parents 2f45c2d + 19a27f8 commit 658d2d0
Showing 1 changed file with 18 additions and 15 deletions.
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

0 comments on commit 658d2d0

Please sign in to comment.