Class: Refinery::BeanstalkQueue

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/refinery/beanstalk_queue.rb

Overview

An interface to beanstalk using SQS-compatible methods.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Loggable

#logger

Constructor Details

#initialize(name = nil, hosts = nil) ⇒ BeanstalkQueue

Construct a BeanstalkQueue instance.

*name: if specified then that “tube” will be used. *host: if specified then those host:port combos will be used.



11
12
13
14
# File 'lib/refinery/beanstalk_queue.rb', line 11

def initialize(name=nil, hosts=nil)
  @name = name.gsub(/_/, '-') # beanstalk does not like underscores in tube names
  @hosts = hosts || ['localhost:11300']
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/refinery/beanstalk_queue.rb', line 5

def name
  @name
end

Instance Method Details

#receive(visibility = nil) ⇒ Object

Get the next message from the queue



17
18
19
# File 'lib/refinery/beanstalk_queue.rb', line 17

def receive(visibility=nil)
  beanstalk.reserve(visibility)
end

#send_message(message) ⇒ Object

Send a message



27
28
29
# File 'lib/refinery/beanstalk_queue.rb', line 27

def send_message(message)
  beanstalk.put(message)
end

#sizeObject

Get the approximate queue size



22
23
24
# File 'lib/refinery/beanstalk_queue.rb', line 22

def size
  beanstalk.stats_tube(name)['current-jobs-ready']
end