gocraft / work

Process background jobs in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Retry failed jobs

dscamargo opened this issue · comments

Anyone have a example how to do a retry strategy with failed jobs using this lib, please ?

you can use maxFails from JobOptions.. by default it uses a default exponential backoff before another retry.. You can also supply a custom backoff function

work.JobOptions{
			Priority:       10,
			MaxFails:       5,
			MaxConcurrency: 100,
			//custom backoff function..
			Backoff: func(job *work.Job) int64 {
				return 600 + int64(math.Pow(10, float64(job.Fails+2)))
			},
		}

hmmm nice.

But my main question is: How do I call retry after an error in my code?

@dscamargo you would just return the error object in the task handler. The library will retry all tasks that get an error returned assuming you have the retries configured.

Nice ! I will try.

Thank you @CodechCFA

Hey folks,
I have a similar query but with a slight change.

Is there a way to tell the worker to retry without incrementing the retry attempted count?

@gwthm-in seeing this now but i was wondering what sort of use case you had in mind
(in case you didn't resolve already)

@sudipidus thanks for getting back. This might not be pure work use case. But lemme try to describe what we are trying to achieve here.

We have an events system which pumps events from kakfa and schedules them to work. And in the work middleware we check the event order (sequential order lets say)., if the event is not in the sequence, we still want to process it, retry it (it's not a failure scenario). Hence the requirement is to retry, but not to increase retry failure count.