Oban: different retry period depending on an error?

As per title, what would you do if you want to reschedule the job for retrying with a different period depending on an error happening inside the job’s perform function?

Our scenario is that we want to start with being very strict with the data we accept from a Kafka queue (the app is listening on messages and is scheduling Oban jobs) – but it’s possible we’ll overdo the strictness and that the Kafka message will actually be valid. For that purpose I want the jobs to remain in a :retryable state but with a different retry period than what’s normally given.

I was thinking I can just snooze the job as that’s not draining its retry count, and this seems like the right fit. My only nitpicky worry is that it doesn’t seem conceptually correct – we are not aiming to snooze it, we aim to retry it later after the validation code has been relaxed – but I can very easily live with that.

Did I overlook a mechanism that people usually use in such scenario?

Also, does a mechanism exist that detects when the app is restarted which causes Oban to immediately retry certain jobs?

I think you should implement your own logic with the backoff callback. Oban.Worker — Oban v2.18.2

4 Likes

Hm, that will work. Since backoff has the Oban.Job parameter I can get all data from the job and then run the validation and if it fails I can then return a different time.

Very nice idea, thank you. I’ll go try it and see if I like it how it behaves.

1 Like

Yeah, this does nicely, thank you.

1 Like