Class: BoringBackup::Notifiers::Sentinel
- Inherits:
-
Object
- Object
- BoringBackup::Notifiers::Sentinel
- Defined in:
- lib/boring_backup/notifiers/sentinel.rb
Constant Summary collapse
- PAYLOAD_VERSION =
1- OPEN_TIMEOUT =
5- READ_TIMEOUT =
10- MAX_ATTEMPTS =
3- LOCAL_HOSTS =
%w[localhost 127.0.0.1 0.0.0.0]
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
-
#initialize(key:, host:) ⇒ Sentinel
constructor
A new instance of Sentinel.
- #notify(result) ⇒ Object
- #ping_url ⇒ Object
Constructor Details
#initialize(key:, host:) ⇒ Sentinel
Returns a new instance of Sentinel.
17 18 19 20 |
# File 'lib/boring_backup/notifiers/sentinel.rb', line 17 def initialize(key:, host:) @key = key @host = host end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
15 16 17 |
# File 'lib/boring_backup/notifiers/sentinel.rb', line 15 def host @host end |
#key ⇒ Object
Returns the value of attribute key.
15 16 17 |
# File 'lib/boring_backup/notifiers/sentinel.rb', line 15 def key @key end |
Instance Method Details
#notify(result) ⇒ 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 |
# File 'lib/boring_backup/notifiers/sentinel.rb', line 26 def notify(result) body = payload(result).to_json attempt = 0 begin attempt += 1 response = post(body) return true if response.is_a?(Net::HTTPSuccess) raise BoringBackup::Error, "#{response.code} #{response.body}" if retryable?(response) warn "Sentinel ping failed: #{response.code} #{response.body}" false rescue => e if attempt < MAX_ATTEMPTS sleep(2**(attempt - 1)) retry end warn "Sentinel ping error after #{attempt} attempts: #{e.}" false end end |
#ping_url ⇒ Object
22 23 24 |
# File 'lib/boring_backup/notifiers/sentinel.rb', line 22 def ping_url URI.join(normalized_host, "/ping/#{key}") end |