Method: Delayed::Worker#reschedule

Defined in:
lib/delayed/worker.rb

#reschedule(job, time = nil) ⇒ Object

Reschedule the job in the future (when a job fails). Uses an exponential scale depending on the number of failed attempts.

[View source]

165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/delayed/worker.rb', line 165

def reschedule(job, time = nil)
  if (job.attempts += 1) < self.class.max_attempts
    time ||= Job.db_time_now + (job.attempts ** 4) + 5
    job.run_at = time
    job.unlock
    job.save!
  else
    say "* [JOB] PERMANENTLY removing #{job.name} because of #{job.attempts} consecutive failures.", Logger::INFO

    if job.payload_object.respond_to? :on_permanent_failure
      say "* [JOB] Running on_permanent_failure hook"
      job.payload_object.on_permanent_failure
    end

    self.class.destroy_failed_jobs ? job.destroy : job.update_attributes(:failed_at => Delayed::Job.db_time_now)
  end
end