Module: Resque::One::ResqueExt

Included in:
Resque
Defined in:
lib/resque/one/resque_ext.rb

Instance Method Summary collapse

Instance Method Details

#dequeue(klass, *args) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/resque/one/resque_ext.rb', line 30

def dequeue(klass, *args)
  job_info = JobInfo.new klass, args

  if job_info.one?
    queue_locker = QueueLocker.new redis, queue_from_class(job_info.klass)
    if args.empty?
      queue_locker.unlock_all job_info.klass
    else
      queue_locker.unlock job_info
    end
  end

  super job_info.klass, *args
end

#enqueue_to(queue, klass, *args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/resque/one/resque_ext.rb', line 5

def enqueue_to(queue, klass, *args)
  job_info = JobInfo.new klass, args
  queue_locker = QueueLocker.new redis, queue

  if !job_info.one? || queue_locker.lock(job_info)
    super queue, job_info.klass, *args
  else
    nil
  end
end

#remove_queue(queue) ⇒ Object



45
46
47
48
49
50
# File 'lib/resque/one/resque_ext.rb', line 45

def remove_queue(queue)
  queue_locker = QueueLocker.new redis, queue
  queue_locker.unlock_all

  super queue
end

#reserve(queue) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/resque/one/resque_ext.rb', line 16

def reserve(queue)
  job = super queue
  return nil if job.nil?

  job_info = JobInfo.parse job.payload

  if job_info.one?
    queue_locker = QueueLocker.new redis, queue
    queue_locker.unlock job_info
  end

  job
end