Class: Resque::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/resque-ext/job.rb

Class Method Summary collapse

Class Method Details

.create_with_loner(queue, klass, *args) ⇒ Object Also known as: create

Overwriting original create method to mark an item as queued

after Resque::Job.create has called Resque.push


14
15
16
17
18
19
20
21
# File 'lib/resque-ext/job.rb', line 14

def self.create_with_loner(queue, klass, *args)
  return create_without_loner(queue, klass, *args) if Resque.inline?
  item = { :class => klass.to_s, :args => args }
  return "EXISTED" if Resque::Plugins::Loner::Helpers.loner_queued?(queue, item)
  job = create_without_loner(queue, klass, *args)
  Resque::Plugins::Loner::Helpers.mark_loner_as_queued(queue, item)
  job
end

.destroy_with_loner(queue, klass, *args) ⇒ Object Also known as: destroy

Overwriting original destroy method to mark all destroyed jobs as unqueued.

Because the original method only returns the amount of jobs destroyed, but not 
the jobs themselves. Hence Resque::Plugins::Loner::Helpers.job_destroy looks almost
as the original method Resque::Job.destroy. Couldn't make it any dry'er.


38
39
40
41
# File 'lib/resque-ext/job.rb', line 38

def self.destroy_with_loner(queue, klass, *args)
  Resque::Plugins::Loner::Helpers.job_destroy(queue, klass, *args) unless Resque.inline?
  destroy_without_loner(queue, klass, *args)
end

.reserve_with_loner(queue) ⇒ Object Also known as: reserve

Overwriting original reserve method to mark an item as unqueued



26
27
28
29
30
# File 'lib/resque-ext/job.rb', line 26

def self.reserve_with_loner(queue)
  item = reserve_without_loner(queue)
  Resque::Plugins::Loner::Helpers.mark_loner_as_unqueued( queue, item ) if item && !Resque.inline?
  item
end