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.
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:
Extended version:
I suggest adding a function that helps to delay a job with proper back-off settings:
It may look like this:
I am curious to hear your thoughts. Maybe there is already something that I am missing.