Class: RockQueue::Beanstalkd

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Beanstalkd

Returns a new instance of Beanstalkd.



13
14
15
16
17
# File 'lib/rock-queue/adapters/beanstalkd.rb', line 13

def initialize(options = {})
  @options = options
  @addr = "#{options[:server]}:#{options[:port]}"
  @obj = Beanstalk::Pool.new([@addr])
end

Instance Attribute Details

#objObject (readonly)

Returns the value of attribute obj.



11
12
13
# File 'lib/rock-queue/adapters/beanstalkd.rb', line 11

def obj
  @obj
end

Instance Method Details

#clearObject



31
32
33
34
35
36
# File 'lib/rock-queue/adapters/beanstalkd.rb', line 31

def clear
  kill_cmd = `which killall`.empty? ? "pkill" : "killall"
  
  system "#{kill_cmd} beanstalkd"
  system "beanstalkd -d -p #{@options[:port]}"
end

#pop(queue) ⇒ Object



24
25
26
27
28
29
# File 'lib/rock-queue/adapters/beanstalkd.rb', line 24

def pop(queue)
  @obj.send(:send_to_rand_conn, :use, queue)
  r = YAML.load(@obj.reserve.body)
  r[0] = Kernel.const_get(r[0])
  r
end

#push(queue, value, *args) ⇒ Object



19
20
21
22
# File 'lib/rock-queue/adapters/beanstalkd.rb', line 19

def push(queue, value, *args)
  @obj.send(:send_to_rand_conn, :use, queue)
  @obj.put [value.name, args].to_yaml 
end

#queuesObject



42
43
44
# File 'lib/rock-queue/adapters/beanstalkd.rb', line 42

def queues
  @obj.list_tubes[@addr].map(&:to_sym)
end

#size(queue) ⇒ Object



38
39
40
# File 'lib/rock-queue/adapters/beanstalkd.rb', line 38

def size(queue)
  @obj.stats_tube(queue)["current-jobs-ready"]
end