Class: ActiveJob::QueueAdapters::ResqueExt::ResqueJobs

Inherits:
Object
  • Object
show all
Defined in:
lib/active_job/queue_adapters/resque_ext.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(jobs_relation, redis:) ⇒ ResqueJobs

Returns a new instance of ResqueJobs.



104
105
106
107
# File 'lib/active_job/queue_adapters/resque_ext.rb', line 104

def initialize(jobs_relation, redis:)
  @jobs_relation = jobs_relation
  @redis = redis
end

Instance Attribute Details

#jobs_relationObject (readonly)

Returns the value of attribute jobs_relation.



100
101
102
# File 'lib/active_job/queue_adapters/resque_ext.rb', line 100

def jobs_relation
  @jobs_relation
end

Instance Method Details

#allObject



117
118
119
# File 'lib/active_job/queue_adapters/resque_ext.rb', line 117

def all
  @all ||= fetch_resque_jobs.collect.with_index { |resque_job, index| deserialize_resque_job(resque_job, index) if resque_job.is_a?(Hash) }.compact
end

#countObject



109
110
111
112
113
114
115
# File 'lib/active_job/queue_adapters/resque_ext.rb', line 109

def count
  if paginated?
    count_fetched_jobs # no direct way of counting jobs
  else
    direct_jobs_count
  end
end

#discard(job) ⇒ Object



142
143
144
145
146
147
148
149
# File 'lib/active_job/queue_adapters/resque_ext.rb', line 142

def discard(job)
  redis.multi do |multi|
    multi.lset(queue_redis_key, job.position, SENTINEL)
    multi.lrem(queue_redis_key, 1, SENTINEL)
  end
rescue Redis::CommandError => error
  handle_resque_job_error(job, error)
end

#discard_allObject



134
135
136
137
138
139
140
# File 'lib/active_job/queue_adapters/resque_ext.rb', line 134

def discard_all
  if jobs_relation.failed? && targeting_all_jobs?
    clear_failed_queue
  else
    discard_all_one_by_one
  end
end

#find_job(job_id) ⇒ Object



151
152
153
# File 'lib/active_job/queue_adapters/resque_ext.rb', line 151

def find_job(job_id)
  jobs_by_id[job_id]
end

#retry_allObject



121
122
123
124
125
126
127
# File 'lib/active_job/queue_adapters/resque_ext.rb', line 121

def retry_all
  if use_batches?
    retry_all_in_batches
  else
    retry_jobs(jobs_relation.to_a.reverse)
  end
end

#retry_job(job) ⇒ Object



129
130
131
132
# File 'lib/active_job/queue_adapters/resque_ext.rb', line 129

def retry_job(job)
  # Not named just +retry+ because it collides with reserved Ruby keyword.
  resque_requeue_and_discard(job)
end