Class: Smartware::ConnectionMonitor

Inherits:
Object
  • Object
show all
Defined in:
lib/smartware/connection_monitor.rb

Instance Method Summary collapse

Constructor Details

#initialize(timeout) ⇒ ConnectionMonitor

Returns a new instance of ConnectionMonitor.



3
4
5
6
# File 'lib/smartware/connection_monitor.rb', line 3

def initialize(timeout)
  @timeout = [ timeout / 5, 1 ].max
  @counter = @timeout
end

Instance Method Details

#runObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/smartware/connection_monitor.rb', line 8

def run
  loop do
    if Smartware.modem.error.nil?
      @counter = @timeout
    else
      if @counter == 0
        Smartware.watchdog.reboot_modem
        @counter = @timeout
      else
        @counter -= 1
      end
    end

    sleep 5
  end
end