[Feature Proposal] [ActiveJob] Allow block to be executed on all retrys not just final retry

Presently, the retry_on method allows you to pass a block to be executed after all permitted attempts have failed. I would like to propose expanding this to allow the block to be executed after each attempt.

This could be configurable, such as an additional parameter that allows a developer to specify execute_block_on: [:always|:final_failure|:before_final_failure] (with better naming eventually) or could be done by passing an argument to the block indicating whether it’s the final failure or not like:

retry_on(SomeException, attempts: 5) do |job, exception, is_final_failure|
  if is_final_failure
    # do stuff when it's the last time
  else
    # do stuff after a failed attempt but before retrying
  end
end

The specific use-case I have in mind for this is sending failure metrics to a stats system or custom logging for the failures.

I like the idea of the extra block argument. Another way perhaps that would open up more use-cases would be to add the current attempt number to the given job?

retry_on(SomeException, attempts: 5) do |job, exception|
  if job.attempt == 5
    # do stuff when it’s the last time
  else
    # do stuff after a failed attempt but before retrying
  end
end