Class: RockQueue::Beanstalkd
- Inherits:
-
Object
- Object
- RockQueue::Beanstalkd
- Defined in:
- lib/rock-queue/adapters/beanstalkd.rb
Instance Attribute Summary collapse
-
#obj ⇒ Object
readonly
Returns the value of attribute obj.
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(options = {}) ⇒ Beanstalkd
constructor
A new instance of Beanstalkd.
- #pop(queue) ⇒ Object
- #push(queue, value, *args) ⇒ Object
- #queues ⇒ Object
- #size(queue) ⇒ Object
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 = @addr = "#{[:server]}:#{[:port]}" @obj = Beanstalk::Pool.new([@addr]) end |
Instance Attribute Details
#obj ⇒ Object (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
#clear ⇒ Object
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 |
#queues ⇒ Object
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 |