Module: JobDispatch::Job

Defined in:
lib/job_dispatch/job.rb

Constant Summary collapse

DEFAULT_EXECUTION_TIMEOUT =
30
PENDING =
0
IN_PROGRESS =
1
COMPLETED =
2
FAILED =
3
STATUS_STRINGS =
{
    PENDING => 'pending',
    IN_PROGRESS => 'in progress',
    COMPLETED => 'completed',
    FAILED => 'failed'
}

Instance Method Summary collapse

Instance Method Details

#failed!(results) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/job_dispatch/job.rb', line 22

def failed!(results)
  # update database
  self.completed_at = Time.now
  self.result = results
  if retry_count && retry_count > 0 && retry_delay && retry_delay > 0
    self.retry_count -= 1
    self.scheduled_at = Time.now + retry_delay.seconds
    self.retry_delay *= 2
    self.status = PENDING
  else
    self.status = FAILED
  end
  save!
end

#succeeded!(results) ⇒ Object



37
38
39
40
41
42
# File 'lib/job_dispatch/job.rb', line 37

def succeeded!(results)
  self.status = COMPLETED
  self.result = results
  self.completed_at = Time.now
  save!
end

#timed_out?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/job_dispatch/job.rb', line 18

def timed_out?
  expire_execution_at < Time.now
end