Class: RockQueue::ResqueQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/rock-queue/adapters/resque.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ResqueQueue

Contructor of Resque adapter



15
16
17
18
# File 'lib/rock-queue/adapters/resque.rb', line 15

def initialize(options)
  Resque.redis = "#{options[:server]}:#{options[:port]}"
  Resque.redis.sadd(:queues, :default)
end

Instance Attribute Details

#objObject (readonly)

Returns the value of attribute obj.



12
13
14
# File 'lib/rock-queue/adapters/resque.rb', line 12

def obj
  @obj
end

Instance Method Details

#clearObject



53
54
55
56
# File 'lib/rock-queue/adapters/resque.rb', line 53

def clear
  Resque.redis.flushall
  Resque.redis.sadd(:queues, :default)
end

#pop(queue) ⇒ Object

Retrieve item from Resque queue



43
44
45
46
# File 'lib/rock-queue/adapters/resque.rb', line 43

def pop(queue)
  job = Resque.reserve(queue)
  [job.payload_class, job.args] if job   
end

#push(queue, value, args) ⇒ Object

Push item from Resque queue



21
22
23
24
25
26
27
28
# File 'lib/rock-queue/adapters/resque.rb', line 21

def push(queue, value, args)
  if !defined?(value.queue)
    value.class_eval do 
      @queue = queue
    end
  end
  Resque.enqueue value, args
end

#push_at(value, time_to_run_at, *args) ⇒ Object

Push items to Resque queue to be picked up by the worker on specified time



31
32
33
34
35
36
37
38
39
40
# File 'lib/rock-queue/adapters/resque.rb', line 31

def push_at(value, time_to_run_at, *args)
  if !defined?(value.queue)
    value.class_eval do 
      @queue = :default
    end
  end
  
  raise "resque_scheduler is required" unless Resque.respond_to?(:enqueue_at)
  Resque.enqueue_at time_to_run_at, value, args
end

#queuesObject



62
63
64
# File 'lib/rock-queue/adapters/resque.rb', line 62

def queues
  Resque.queues.sort.map(&:to_sym)
end

#register_worker(worker) ⇒ Object

Register worker for web interface



49
50
51
# File 'lib/rock-queue/adapters/resque.rb', line 49

def register_worker(worker)
  Resque.redis.sadd(:workers, worker)
end

#size(queue) ⇒ Object



58
59
60
# File 'lib/rock-queue/adapters/resque.rb', line 58

def size(queue)
  Resque.size(queue)
end