Class: Wakame::Triggers::ShutdownUnusedVM

Inherits:
Wakame::Trigger show all
Defined in:
lib/wakame/triggers/shutdown_unused_vm.rb

Constant Summary

Constants included from AttributeHelper

AttributeHelper::CLASS_TYPE_KEY, AttributeHelper::CONVERT_CLASSES, AttributeHelper::PRIMITIVE_CLASSES

Instance Method Summary collapse

Methods inherited from Wakame::Trigger

#agent_monitor, #cleanup, #command_queue, #master, #trigger_action

Methods included from AttributeHelper

#dump_attrs, #retrieve_attr_attribute

Methods included from FilterChain

included, #run_filter

Instance Method Details

#register_hooks(cluster_id) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/wakame/triggers/shutdown_unused_vm.rb', line 4

def register_hooks(cluster_id)
  event_subscribe(Event::AgentPong) { |event|
    if event.agent.services.empty? &&
        Time.now - event.agent.last_service_assigned_at > Wakame.config.unused_vm_live_period &&
        event.agent.agent_id != master.attr[:instance_id]
      Wakame.log.info("Shutting the unused VM down: #{event.agent.agent.id}")
      trigger_action(ShutdownVM.new(event.agent))
    end
  }
end