Class: Woodhouse::Runner

Inherits:
Object
  • Object
show all
Includes:
Celluloid, Util
Defined in:
lib/woodhouse/runner.rb

Overview

The abstract base class for actors in charge of finding and running jobs of a given type. Runners will be allocated for each Woodhouse::Layout::Worker in a layout. Woodhouse::Layout::Worker#threads indicates how many Runners should be spawned for each job type.

The lifecycle of a Runner is to be created by Woodhouse::Scheduler::WorkerSet, and to automatically begin subscribing as soon as it is initialized. At some point, the actor will receive the spin_down message, at which case it must cease all work and return from subscribe.

Whenever a Runner receives a job on its queue, it should convert it into a Workling::Job and pass it to service_job after confirming with can_service_job? that this is an appropriate job for this queue.

Runners should always subscribe to queues in ack mode. Messages should be acked after they finish, and rejected if the job is inappropriate for this worker or if it raises an exception.

TODO: document in more detail the contract between Runner and Dispatcher over AMQP exchanges, and how Woodhouse uses AMQP to distribute jobs.

Instance Method Summary collapse

Constructor Details

#initialize(worker, config) ⇒ Runner

Returns a new instance of Runner.



27
28
29
30
31
# File 'lib/woodhouse/runner.rb', line 27

def initialize(worker, config)
  @worker = worker
  @config = config
  @config.logger.debug "Thread for #{@worker.describe} ready and waiting for jobs"
end

Instance Method Details

#spin_downObject

Implement this in a subclass. When this message is received by an actor, it should finish whatever job it is currently doing, gracefully disconnect from AMQP, and stop the subscribe loop.

Raises:

  • (NotImplementedError)


36
37
38
# File 'lib/woodhouse/runner.rb', line 36

def spin_down
  raise NotImplementedError, "implement #spin_down in a subclass of Woodhouse::Runner"
end