Class: Trinidad::Lifecycle::Host::RollingReload::Takeover

Inherits:
Base
  • Object
show all
Defined in:
lib/trinidad/lifecycle/host/rolling_reload.rb

Overview

:nodoc

Constant Summary

Constants inherited from Base

Base::EVENTS

Instance Method Summary collapse

Methods inherited from Base

#after_destroy, #after_init, #after_stop, #before_destroy, #before_init, #before_start, #before_stop, #configure_start, #configure_stop, #lifecycleEvent, #periodic, #start, #stop

Constructor Details

#initialize(context) ⇒ Takeover

Returns a new instance of Takeover.



58
59
60
# File 'lib/trinidad/lifecycle/host/rolling_reload.rb', line 58

def initialize(context)
  @old_context = context
end

Instance Method Details

#after_start(event) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/trinidad/lifecycle/host/rolling_reload.rb', line 62

def after_start(event)
  new_context = event.lifecycle
  new_context.remove_lifecycle_listener(self) # GC old context

  logger.debug "Stoping the old Context for [#{@old_context.path}]"

  @old_context.stop
  @old_context.work_dir = nil # make sure it's not deleted
  @old_context.destroy
  # NOTE: name might not be changed once added to a parent
  #new_context.name = @old_context.name
  super
end

#failed!(new_context) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/trinidad/lifecycle/host/rolling_reload.rb', line 76

def failed!(new_context)
  # NOTE: this will also likely destroy() the child - new context :
  @old_context.parent.remove_child new_context
  logger.info "Failed to start new Context for [#{@old_context.path}] " + 
              "(check application logs) keeping the old one running ..."
  new_context.remove_lifecycle_listener(self)
end