mbuhot/ecto_job

Retry only for specific failures

mkorszun opened this issue · 3 comments

Is it possible to distinguish between execution failures, and retry only on desired errors?

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?

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.

Closing this issue for now. We may like to revisit the idea once #45 lands.