Class: Toro::Middleware::Server::Retry

Inherits:
Object
  • Object
show all
Defined in:
lib/toro/middleware/server/retry.rb

Instance Method Summary collapse

Instance Method Details

#call(job, worker) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/toro/middleware/server/retry.rb', line 5

def call(job, worker)
  begin
    yield
  rescue Exception => exception
    if worker.toro_options[:retry_interval]
      interval = worker.toro_options[:retry_interval]
      job.reload
      job.properties ||= {}
      job.properties['retry:errors'] ||= []
      job.properties['retry:errors'] << "#{exception.class.name} -- #{exception.message} -- #{Time.now}"
      job.status = 'scheduled'
      job.scheduled_at = Time.now + interval
      job.save
    end
    raise exception
  end
end