Class: Opee::AskQueue

Inherits:
Queue show all
Defined in:
lib/opee/askqueue.rb

Overview

Implements a work queue Actor that will distribute method calls to Actors that volunteer to execute those methods. The primary use is to distribute work across multiple workers.

Constant Summary

Constant Summary

Constants inherited from Actor

Opee::Actor::CLOSING, Opee::Actor::RUNNING, Opee::Actor::STEP, Opee::Actor::STOPPED

Instance Attribute Summary

Attributes inherited from Actor

#name, #state

Instance Method Summary (collapse)

Methods inherited from Queue

#add, #ask, #busy?, #queue_count, #ready, #set_options, #work_queue_size, #worker_count

Methods inherited from Actor

#ask, #ask_timeout, #ask_timeout=, #busy?, #close, #max_queue_count, #max_queue_count=, #method_missing, #on_idle, #priority_ask, #queue_count, #set_options, #start, #step, #stop, #timeout_ask, #wakeup

Constructor Details

- (AskQueue) initialize(options = {})

A new instance of AskQueue



8
9
10
# File 'lib/opee/askqueue.rb', line 8

def initialize(options={})
  super(options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Opee::Actor

Instance Method Details

- (Object) add_method(op, *args)

Queues an operation and arguments to be handed off to a worker when the worker is ready.

Parameters:

  • op (Symbol)

    method to queue for the Actor

  • args (Array)

    arguments to the op method

Raises:



16
17
18
# File 'lib/opee/askqueue.rb', line 16

def add_method(op, *args)
  ask(:add, Act.new(op, args))
end

- (Object) ask_worker(worker, job) (private)

Asks the worker to invoke the method of an Act Object.

Raises:

  • (NoMethodError)


23
24
25
26
# File 'lib/opee/askqueue.rb', line 23

def ask_worker(worker, job)
  raise NoMethodError.new("undefined method for #{job.class}. Expected a method invocation") unless job.is_a?(Actor::Act)
  worker.ask(job.op, *job.args)
end