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.

Direct Known Subclasses

Woodhouse::Runners::BunnyRunner, Woodhouse::Runners::DummyRunner, Woodhouse::Runners::FileRunner, Woodhouse::Runners::HotBunniesRunner

Instance Method Summary (collapse)

Constructor Details

- (Runner) initialize(worker, config)

Returns a new instance of Runner



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

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

Instance Method Details

- (Object) current_status



41
42
43
# File 'lib/woodhouse/runner.rb', line 41

def current_status
  @status
end

- (Object) spin_down

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)


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

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