Class: Eye::Trigger::StartingGuard
- Inherits:
-
Eye::Trigger
- Object
- Eye::Trigger
- Eye::Trigger::StartingGuard
- Defined in:
- lib/eye/trigger/starting_guard.rb
Constant Summary
Constants inherited from Eye::Trigger
Instance Attribute Summary
Attributes inherited from Eye::Trigger
Instance Method Summary collapse
- #check(transition) ⇒ Object
- #check_start ⇒ Object
-
#initialize(*args) ⇒ StartingGuard
constructor
A new instance of StartingGuard.
Methods inherited from Eye::Trigger
create, #defer, #exec_proc, #filter_transition, get_class, #inspect, #logger_sub_tag, #logger_tag, name_and_class, #notify, register, requires, #run_in_process_context, validate!
Methods included from Dsl::Validation
Constructor Details
#initialize(*args) ⇒ StartingGuard
Returns a new instance of StartingGuard.
15 16 17 18 19 20 |
# File 'lib/eye/trigger/starting_guard.rb', line 15 def initialize(*args) super @retry_count = 0 @reretry_count = 0 end |
Instance Method Details
#check(transition) ⇒ Object
22 23 24 |
# File 'lib/eye/trigger/starting_guard.rb', line 22 def check(transition) check_start if transition.to_name == :starting end |
#check_start ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/eye/trigger/starting_guard.rb', line 26 def check_start @retry_count += 1 condition = defer { exec_proc(:should) } if condition info "ok, process ready to start #{condition.inspect}" @retry_count = 0 @reretry_count = 0 return else info 'false executed condition' end new_time = nil if every if times if @retry_count < times new_time = Time.now + every process.schedule_in every, :conditional_start, Eye::Reason::StartingGuard.new('starting_guard, retry start') else @retry_count = 0 @reretry_count += 1 if retry_in && (!retry_times || (@reretry_count < retry_times)) new_time = Time.now + retry_in process.schedule_in retry_in, :conditional_start, Eye::Reason::StartingGuard.new('starting_guard, reretry start') end end else new_time = Time.now + every process.schedule_in every, :conditional_start, Eye::Reason::StartingGuard.new('starting_guard, retry start') end end retry_msg = new_time ? ", retry at '#{Eye::Utils.human_time2(new_time.to_i)}'" : '' process.switch :unmonitoring, Eye::Reason::StartingGuard.new("starting_guard, failed condition#{retry_msg}") raise Eye::Process::StateError, 'starting_guard, refused to start' end |