Retry only for specific failures
mkorszun opened this issue · 3 comments
mkorszun commented
Is it possible to distinguish between execution failures, and retry only on desired errors?
mbuhot commented
You could use rescue
in your perform
function to catch exceptions?
def perform(original_multi = %Ecto.Multi{}, job = %{}) do
final_multi = do_job_logic(original_multi, job)
Repo.transaction(final_multi) # success, commit all changes
rescue
e in SomeError -> reraise e, __STACKTRACE__ # fail the job in this specific case, it will be retried after delay
otherwise -> Repo.transaction(original_multi) # complete the job without other changes, will not be retried
end
Other job libraries I've used provided hooks for before/after middleware, eg Exq. Do you think a middleware pipeline would be useful for EctoJob to handle the failure/retry logic?
mkorszun commented
Thanks for the quick response. Yes, I find it quite useful to have some post error callbacks where I could do some post processing and control job retries. Still evaluating other elixir solutions, but really like ecto_job
for its simplicity. If we will decide to use ecto_job
we would be definitely interested in this feature and ready to contribute.