Class: RockQueue::Base
- Inherits:
-
Object
- Object
- RockQueue::Base
- Defined in:
- lib/rock-queue.rb
Class Method Summary collapse
-
.logger ⇒ Object
Returns Rock Queue logger.
Instance Method Summary collapse
-
#initialize(adapter, *options) ⇒ Base
constructor
Initializes the whole thing and makes the connection to the queueing server using selected adapter (passed as lowercased symbol).
-
#method_missing(sym, *args, &block) ⇒ Object
Calling adapter method.
-
#push(value, *args) ⇒ Object
Pushes the value (in our case it should always be an object) onto the queue using previously selected adapter.
-
#receive ⇒ Object
Pulls the data off the queue.
Constructor Details
#initialize(adapter, *options) ⇒ Base
Initializes the whole thing and makes the connection to the queueing server using selected adapter (passed as lowercased symbol)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rock-queue.rb', line 32 def initialize(adapter, *) # Any better way to do this? :-) = .first if .include?(:server) && .include?(:port) case adapter when :beanstalkd @adapter = Beanstalkd.new() when :resque @adapter = ResqueQueue.new() when :delayed_job @adapter = DelayedJob.new() end else raise ArgumentError end # Initialize logger @@logger = Logger.new([:log].nil? ? STDOUT : [:log]) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
Calling adapter method
74 75 76 |
# File 'lib/rock-queue.rb', line 74 def method_missing(sym, *args, &block) @adapter.send sym, *args, &block end |
Class Method Details
.logger ⇒ Object
Returns Rock Queue logger
79 80 81 |
# File 'lib/rock-queue.rb', line 79 def self.logger @@logger end |
Instance Method Details
#push(value, *args) ⇒ Object
Pushes the value (in our case it should always be an object) onto the queue using previously selected adapter
55 56 57 |
# File 'lib/rock-queue.rb', line 55 def push(value, *args) @adapter.push(value, args) end |
#receive ⇒ Object
Pulls the data off the queue. There are two ways to do so:
-
Call receive with no block (gets you a single item)
-
Pass a block to it (creates and endles loop that constantly pulls items from the queue as they become available)
All calls to the queueing server are made through the previosuly selected adaper.
64 65 66 67 68 69 70 71 |
# File 'lib/rock-queue.rb', line 64 def receive if block_given? obj, args = @adapter.pop yield QueueObject.new(obj, args) if obj else raise 'No block given' end end |