Search code examples
ruby-on-rails-5delayed-jobrails-activejob

Rails5, how to retry perform an ActiveJob a specific number of times (max attempts)


Right now I have my Background processes running with DelayedJobs, I see very convenient the max_attempts functionality on DelayedJob, how can I replicate this in ActiveJob?

Is this dependent on the queue system? has ActiveJob any abstraction configuration for this?


Solution

  • The gem ActiveJob::Retry did the trick:

    class MyJob < ActiveJob::Base
      include ActiveJob::Retry.new(
        :strategy => :variable,
        :delays => [10.seconds, 1.minute, 10.minutes, 15.minutes]
      )
    end