opsgenie-heartbeat 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd5d3723a4435fe8e9cfd5025915f6a0f03104c37b44443222c3b5c9d48ddd4a
4
- data.tar.gz: de5ea23f4ffb8fae833de5f2c82c9308d6320b5c48586d7ec894da2c79ade429
3
+ metadata.gz: 40ad93c29a50145b21401962688273ffb38cd994bfd6d222d82ea43baeafaa5e
4
+ data.tar.gz: 055e1f4ab36b7d670ef8a85b9989f60a862833cd3085f0865c1997bd0950d6ac
5
5
  SHA512:
6
- metadata.gz: 6bb8dbc25e6c83bc96fe00a10a0121d0e805954a89930e0318f6e60f2658d15a367ff91fc5f4a1c41c4447fbcb7914e078455e528a25a0a07c2eff39017dc3a3
7
- data.tar.gz: '018d7fdb1db8ee6299451879f1edd0ffb9bae6412b019b63054764264b40a21f82ffa404f979491c5341b535461b9fd8004dddfef8582efc4179ed7e36954f5b'
6
+ metadata.gz: 1b366b335612b50cf981e6be0e16f11be22cde7c6aa36804ab940451f4ddc443d025fd804011935b2ae4230f5e4879323a1f52bfeebe1ef305dd2435fbd5163f
7
+ data.tar.gz: bd62e408cda81d65e689e28bbc2b6f109f761cab3e29e398a1d5dd1f7df137b3a46a9729777197a284bed2c5e4a18b78c4f2e8540c8830119d7c54e8e022cc6e
@@ -1,3 +1,6 @@
1
+ ## Updates in version 0.4:
2
+ - ability to configure retries
3
+
1
4
  ## Updates in version 0.3:
2
5
  - ability to configure a default team
3
6
 
data/README.md CHANGED
@@ -53,6 +53,10 @@ In yours initializers folder, define new file with:
53
53
  #will set the team to Myteam on all new heartbeats
54
54
  #you can override when you create the heartbeat.
55
55
  config.default_team = 'Myteam'
56
+
57
+ #retry timedout api calls upto the specified number of times, with a random backoff
58
+ #default is no retries
59
+ config.retries = 2
56
60
  end
57
61
  ```
58
62
 
@@ -12,13 +12,14 @@ module Opsgenie
12
12
  name = configuration.name_transformer.call(name)
13
13
  begin
14
14
  uri = URI.parse("https://api.opsgenie.com/v2/heartbeats/#{Rack::Utils.escape name}/ping")
15
- http = Net::HTTP.new(uri.host, uri.port)
16
- http.use_ssl = true
17
- response = http.get(uri.path, {'Authorization': "GenieKey #{configuration.api_key}"})
18
- if !response.is_a?(Net::HTTPSuccess)
19
- configuration.logger.info("Error creating or updating heartbeat: #{response}") if configuration.logger
15
+ with_timeout_retries do
16
+ http = Net::HTTP.new(uri.host, uri.port)
17
+ http.use_ssl = true
18
+ response = http.get(uri.path, {'Authorization': "GenieKey #{configuration.api_key}"})
19
+ if !response.is_a?(Net::HTTPSuccess)
20
+ configuration.logger.info("Error creating or updating heartbeat: #{response}") if configuration.logger
21
+ end
20
22
  end
21
-
22
23
  rescue => e
23
24
  resolve_exception e
24
25
  end
@@ -30,11 +31,13 @@ module Opsgenie
30
31
  name = configuration.name_transformer.call(name)
31
32
 
32
33
  uri = URI.parse(url_for_resource(:get, name))
33
- http = Net::HTTP.new(uri.host, uri.port)
34
- http.use_ssl = true
35
- response = http.get(uri.path, {'Authorization': "GenieKey #{configuration.api_key}"})
36
- unless response.is_a?(Net::HTTPSuccess)
37
- create(name: original_name, description: description, interval: interval, unit: unit, enabled: enabled, team: team)
34
+ with_timeout_retries do
35
+ http = Net::HTTP.new(uri.host, uri.port)
36
+ http.use_ssl = true
37
+ response = http.get(uri.path, {'Authorization': "GenieKey #{configuration.api_key}"})
38
+ unless response.is_a?(Net::HTTPSuccess)
39
+ create(name: original_name, description: description, interval: interval, unit: unit, enabled: enabled, team: team)
40
+ end
38
41
  end
39
42
  end
40
43
 
@@ -66,6 +69,24 @@ module Opsgenie
66
69
 
67
70
  private
68
71
 
72
+ def with_timeout_retries
73
+ attempts = 0
74
+ begin
75
+ yield
76
+ rescue Net::OpenTimeout, Net::ReadTimeout => e
77
+ if attempts < (configuration.retries || 0)
78
+ configuration.logger.info("Retrying opsgenie api call after timeout #{e.message}")
79
+ attempts += 1
80
+ sleep(rand(2**attempts))
81
+ retry
82
+ else
83
+ raise
84
+ end
85
+ end
86
+ end
87
+
88
+
89
+
69
90
  def url_for_resource(verb, name)
70
91
  if verb == :post
71
92
  'https://api.opsgenie.com/v2/heartbeats'
@@ -9,7 +9,7 @@ module Opsgenie
9
9
  end
10
10
 
11
11
  class Config
12
- attr_accessor :enabled, :api_key, :name_transformer, :logger, :raise_error, :default_team
12
+ attr_accessor :enabled, :api_key, :name_transformer, :logger, :raise_error, :default_team, :retries
13
13
 
14
14
  def name_transformer
15
15
  @name_transformer || ->(name){name}
@@ -1,5 +1,5 @@
1
1
  module Opsgenie
2
2
  module Heartbeat
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opsgenie-heartbeat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dressipi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-25 00:00:00.000000000 Z
11
+ date: 2018-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  version: '0'
97
97
  requirements: []
98
98
  rubyforge_project:
99
- rubygems_version: 2.7.3
99
+ rubygems_version: 2.7.6
100
100
  signing_key:
101
101
  specification_version: 4
102
102
  summary: OpsGenie Heartbeat version 2