Module: RockQueue

Extended by:
RockQueue
Included in:
RockQueue
Defined in:
lib/rock-queue.rb,
lib/rock-queue/web.rb,
lib/rock-queue/config.rb,
lib/rock-queue/errors.rb,
lib/rock-queue/worker.rb,
lib/rock-queue/notifiers.rb,
lib/rock-queue/queue_object.rb,
lib/rock-queue/adapters/resque.rb,
lib/rock-queue/adapters/beanstalkd.rb,
lib/rock-queue/active_record_helper.rb,
lib/rock-queue/adapters/delayed_job.rb,
lib/rock-queue/notifiers/email_notifier.rb

Defined Under Namespace

Modules: ActiveRecordHelper Classes: AdapterNotSupported, Beanstalkd, Config, DelayedJob, EmailNotifier, NoClassError, Notifiers, QueueObject, QueueingServerNotRunning, ResqueQueue, Web, Worker

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object

Calling adapter method



83
84
85
# File 'lib/rock-queue.rb', line 83

def method_missing(sym, *args, &block)
  adapter.send sym, *args, &block
end

Instance Method Details

#adapterObject

return current connection



46
47
48
49
50
51
52
# File 'lib/rock-queue.rb', line 46

def adapter
  if @adapter
    @adapter
  else
    raise RuntimeError, "RockQueue is not connected. Use setup"
  end
end

#disconnectObject



41
42
43
# File 'lib/rock-queue.rb', line 41

def disconnect
  @adapter = nil
end

#loggerObject



58
59
60
# File 'lib/rock-queue.rb', line 58

def logger
  @logger
end

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



54
55
56
# File 'lib/rock-queue.rb', line 54

def push(queue, value, *args)
  adapter.push(queue, value, args)
end

#receive(queue) ⇒ 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 selecte adaper.



68
69
70
71
72
73
74
75
# File 'lib/rock-queue.rb', line 68

def receive(queue)
  if block_given?
    obj, args = @adapter.pop(queue)
    yield QueueObject.new(obj, args) if obj
  else
    raise 'No block given'
  end
end

#register_worker(worker) ⇒ Object

Register worker for web interface



78
79
80
# File 'lib/rock-queue.rb', line 78

def register_worker(worker)
  @adapter.register_worker(worker) if @adapter.respond_to?(:register_worker)
end

#setup(options) ⇒ Object

setup a connection options: adapter, server, port, log



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rock-queue.rb', line 27

def setup(options)
  case options[:adapter]
  when :beanstalkd
    @adapter = Beanstalkd.new(options)
  when :resque
    @adapter = ResqueQueue.new(options)
  when :delayed_job
    @adapter = DelayedJob.new(options)
  else
    raise ArgumentError
  end
  @logger = Logger.new(options[:log].nil? ? STDOUT : options[:log])
end