Class: Refinery::BeanstalkQueue
- Inherits:
-
Object
- Object
- Refinery::BeanstalkQueue
- Includes:
- Loggable
- Defined in:
- lib/refinery/beanstalk_queue.rb
Overview
An interface to beanstalk using SQS-compatible methods.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name = nil, hosts = nil) ⇒ BeanstalkQueue
constructor
Construct a BeanstalkQueue instance.
-
#receive(visibility = nil) ⇒ Object
Get the next message from the queue.
-
#send_message(message) ⇒ Object
Send a message.
-
#size ⇒ Object
Get the approximate queue size.
Methods included from Loggable
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
#name ⇒ Object (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 () beanstalk.put() end |
#size ⇒ Object
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 |