Class: Workerholic::JobRetry

Inherits:
Object
  • Object
show all
Defined in:
lib/workerholic/job_retry.rb

Constant Summary collapse

MAX_RETRY_ATTEMPTS =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ JobRetry

Returns a new instance of JobRetry.



7
8
9
10
# File 'lib/workerholic/job_retry.rb', line 7

def initialize(options={})
  @job = options[:job]
  @sorted_set = options[:sorted_set] || SortedSet.new('workerholic:scheduled_jobs')
end

Instance Attribute Details

#jobObject (readonly)

Returns the value of attribute job.



3
4
5
# File 'lib/workerholic/job_retry.rb', line 3

def job
  @job
end

#sorted_setObject (readonly)

Returns the value of attribute sorted_set.



3
4
5
# File 'lib/workerholic/job_retry.rb', line 3

def sorted_set
  @sorted_set
end

#stats_storageObject (readonly)

Returns the value of attribute stats_storage.



3
4
5
# File 'lib/workerholic/job_retry.rb', line 3

def stats_storage
  @stats_storage
end

Instance Method Details

#retryObject



12
13
14
15
16
17
18
19
20
# File 'lib/workerholic/job_retry.rb', line 12

def retry
  return if job.retry_count >= MAX_RETRY_ATTEMPTS

  increment_retry_count
  schedule_job_for_retry
  Workerholic.manager
             .scheduler
             .schedule(JobSerializer.serialize(job), job.execute_at)
end