Class: SyslogTls::HostBackoffSpecs

Inherits:
Object
  • Object
show all
Defined in:
lib/syslog_tls/host_backoff_specs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(retries_to_do, host_ip_port) ⇒ HostBackoffSpecs

Returns a new instance of HostBackoffSpecs.



7
8
9
10
11
12
# File 'lib/syslog_tls/host_backoff_specs.rb', line 7

def initialize(retries_to_do, host_ip_port)
  @retriesToDo = retries_to_do
  @hostIPport = host_ip_port
  @failTime = nil
  @baseThreshold = 2
end

Instance Attribute Details

#hostIPportObject

Returns the value of attribute hostIPport.



5
6
7
# File 'lib/syslog_tls/host_backoff_specs.rb', line 5

def hostIPport
  @hostIPport
end

#retriesToDoObject

Returns the value of attribute retriesToDo.



5
6
7
# File 'lib/syslog_tls/host_backoff_specs.rb', line 5

def retriesToDo
  @retriesToDo
end

Instance Method Details

#canwriteObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/syslog_tls/host_backoff_specs.rb', line 14

def canwrite
  time_passed_since_failure = -1
  if @failTime != nil
    time_passed_since_failure = Time.now - @failTime
    time_passed_since_failure = time_passed_since_failure.round(2)
  end
  if time_passed_since_failure == -1
    return 1
  end
  backoffTime = @baseThreshold ** @retriesToDo
  if backoffTime > 1800
    backoffTime = 1800
  end
  if time_passed_since_failure > backoffTime
    pp "canwrite writting after backoff :: time_passed_since_failure" + time_passed_since_failure.to_s + " time :: " + Time.now.to_s
    return 1
  else
    return 0
  end
end

#failtowriteObject



35
36
37
38
39
# File 'lib/syslog_tls/host_backoff_specs.rb', line 35

def failtowrite
  @retriesToDo += 1
  @failTime = Time.now
  pp "failtowrite :: retriesToDo :: " + @retriesToDo.to_s + " failTime :: " + Time.now.to_s
end

#resetRetriesObject



41
42
43
44
45
# File 'lib/syslog_tls/host_backoff_specs.rb', line 41

def resetRetries
  @retriesToDo = 0
  @failTime = nil
  pp "resetRetries :: retriesToDo :: " + @retriesToDo.to_s + " failTime :: " + @failTime.to_s
end