Breaking Down Large Jobs into Safely Retriable Parts
CompleteOrderJob has three steps: charge the user, send an email, and request fulfillment. If each step were its own job, the failure mode you simulated above would not result in multiple charges for the order. Let’s set that up by changing CompleteOrderJob to queue a new job called SendOrderNotificationEmailJob that will then queue another new job named RequestOrderFulfillmentJob. As you can see from the image here, this should solve the problem.
A flowchart showing the CompleteOrderJob queuing the job SendOrderNotificationEmailJob, which then queues the job RequestOrderFulfillmentJob. If ...
Get Ruby on Rails Background Jobs with Sidekiq now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.