Class: Woodhouse::Scheduler

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

Defined Under Namespace

Classes: SpunDown, WorkerSet

Instance Method Summary (collapse)

Constructor Details

- (Scheduler) initialize(config)



63
64
65
66
# File 'lib/woodhouse/scheduler.rb', line 63

def initialize(config)
  @config = config
  @worker_sets = {}
end

Instance Method Details

- (Object) remove_worker(worker)



98
99
100
# File 'lib/woodhouse/scheduler.rb', line 98

def remove_worker(worker)
  @worker_sets.delete(worker)
end

- (Boolean) running_worker?(worker)



85
86
87
# File 'lib/woodhouse/scheduler.rb', line 85

def running_worker?(worker)
  @worker_sets.has_key?(worker)
end

- (Object) spin_down



89
90
91
92
93
94
95
96
# File 'lib/woodhouse/scheduler.rb', line 89

def spin_down
  @spinning_down = true
  @config.logger.debug "Spinning down all workers"
  @worker_sets.each do |worker, set|
    set.spin_down
    set.terminate
  end
end

- (Object) start_worker(worker)



68
69
70
71
72
73
74
75
76
# File 'lib/woodhouse/scheduler.rb', line 68

def start_worker(worker)
  @config.logger.debug "Starting worker #{worker.describe}"
  unless @worker_sets.has_key?(worker)
    @worker_sets[worker] = WorkerSet.new_link(Celluloid.current_actor, worker, @config)
    true
  else
    false
  end
end

- (Object) stop_worker(worker, wait = false)



78
79
80
81
82
83
# File 'lib/woodhouse/scheduler.rb', line 78

def stop_worker(worker, wait = false)
  if set = @worker_sets[worker]
    @config.logger.debug "Spinning down worker #{worker.describe}"
    set.spin_down
  end
end

- (Object) worker_set_died(actor, reason)



102
103
104
105
106
107
108
109
110
111
# File 'lib/woodhouse/scheduler.rb', line 102

def worker_set_died(actor, reason)
  if reason
    @config.logger.info "Worker set died (#{reason.class}: #{reason.message}). Spinning down."
    begin
      spin_down
    ensure
      raise reason
    end
  end
end