Class: WebChecker::Workflow
- Inherits:
-
Object
- Object
- WebChecker::Workflow
- Defined in:
- lib/web_checker/workflow.rb
Instance Attribute Summary collapse
-
#attempts ⇒ Object
readonly
Returns the value of attribute attempts.
-
#checker ⇒ Object
readonly
Returns the value of attribute checker.
Instance Method Summary collapse
- #cancel ⇒ Object
-
#initialize(options) ⇒ Workflow
constructor
A new instance of Workflow.
- #run ⇒ Object
Constructor Details
#initialize(options) ⇒ Workflow
Returns a new instance of Workflow.
9 10 11 12 13 14 15 |
# File 'lib/web_checker/workflow.rb', line 9 def initialize() @options = .dup WebChecker::Notifications.instance.setup(@options) @options['threshold'] = @options['threshold'].map(&:to_i) @checker = WebChecker::Http.new(['url']) @attempts = 0 end |
Instance Attribute Details
#attempts ⇒ Object (readonly)
Returns the value of attribute attempts.
7 8 9 |
# File 'lib/web_checker/workflow.rb', line 7 def attempts @attempts end |
#checker ⇒ Object (readonly)
Returns the value of attribute checker.
7 8 9 |
# File 'lib/web_checker/workflow.rb', line 7 def checker @checker end |
Instance Method Details
#cancel ⇒ Object
35 36 37 |
# File 'lib/web_checker/workflow.rb', line 35 def cancel EventMachine.cancel_timer(@timer) if self.instance_variable_defined?(:@timer) && EventMachine.reactor_running? end |
#run ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/web_checker/workflow.rb', line 17 def run if @checker.accessible? WebChecker::Notifications.instance.notify if @attempts > 0 @attempts = 0 else @attempts += 1 if @options['threshold'].include?(@attempts) WebChecker::Notifications.instance.notify_broken(@attempts) end end if EventMachine.reactor_running? @timer = EventMachine.add_timer(@options['refresh_rate']) do run end end end |