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

#initialize(config) ⇒ Scheduler

Returns a new instance of Scheduler



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

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

Instance Method Details

#remove_worker(worker) ⇒ Object



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

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

#running_worker?(worker) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#spin_downObject



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

#start_worker(worker) ⇒ Object



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

#stop_worker(worker, wait = false) ⇒ Object



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

#worker_set_died(actor, reason) ⇒ Object



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