Skip to content

Consider adding a method to comfortably delay failing jobs #29

Description

@27182818284590

In my apps, I want to release failing jobs back to the tube with lower priority and with increasing delay.
A job already has all the necessary metadata, but I would love to avoid repeating the same calculations over and over.

Compact-ish version:

prio := uint32(job.Stats.Releases) * job.Stats.Priority
delay := time.Duration(job.Stats.Releases) * job.Stats.Delay
if err := job.ReleaseWithParams(ctx, prio, delay); err != nil {
    logger.Error("Failed to release a failing job", slog.Any("err", err))
}
return

Extended version:

delay := time.Duration(job.Stats.Releases) * job.Stats.Delay
if delay > maxDelay { 
    delay = maxDelay
}
prio := uint32(job.Stats.Releases) * job.Stats.Priority
if prio > maxPrio { 
    prio = maxPrio
}
if err := job.ReleaseWithParams(ctx, prio, delay); err != nil {
    logger.Error("Failed to release a failing job", 
        slog.Any("job_stats", job.Stats), 
        slog.Any("err", err),
    )
}
return

I suggest adding a function that helps to delay a job with proper back-off settings:

It may look like this:

if err := job.ReleaseWithParams(ctx, job.BackoffParams(maxDelay)); err != nil {
    logger.Error("Failed to release a failing job", slog.Any("err", err))
}
return

I am curious to hear your thoughts. Maybe there is already something that I am missing.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions