Skip to content

Conversation

@GustavoCaso
Copy link
Contributor

@GustavoCaso GustavoCaso commented Dec 23, 2019

With this new callback, we can provide developers with a way to hook in the iteration API before a job gets reenqueued.

Currently, with the current behaviour, we only provide the callback shutdown which will be called every time a job gets reenqueued or at the end of the job when all iterations are executed.

But if the developer wants to execute some sort of validation on the on_shutdown callback to avoid a new job to be reenqueued, that is not possible.

By providing this new callback we allow developers to stop the iteration if something is wrong by using :abort or if they find that the current iteration failed they could modify the job before the new iteration gets reenqueued.

class MyJob < ActiveJob::Base
  include JobIteration::Iteration

  on_reenqueue do |job|
    # check if everything worked with the previous iteration
    job.cursor_position = job.cursor_position - 1 # For example
  end

  ......
end

@GustavoCaso GustavoCaso force-pushed the add-reenqueue-callback branch 2 times, most recently from 55baa66 to 15a8997 Compare December 23, 2019 18:55
@GustavoCaso GustavoCaso force-pushed the add-reenqueue-callback branch from 15a8997 to 8f976cc Compare December 23, 2019 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant