Skip to content

Commit

Permalink
Add retries for Timeouts and HTTP errors (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
johanek authored and sstarcher committed Mar 15, 2017
1 parent 8429821 commit 4b238ab
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions bin/handler-pagerduty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def handle(pd_client = nil)
description_prefix = description_prefix()
proxy_settings = proxy_settings()
begin
tries ||= 3
Timeout.timeout(10) do
if proxy_settings['proxy_host']
pagerduty = pd_client || Pagerduty.new(api_key,
Expand All @@ -109,12 +110,20 @@ def handle(pd_client = nil)
end
puts 'pagerduty -- ' + @event['action'].capitalize + 'd incident -- ' + incident_key
rescue Net::HTTPServerException => error
puts 'pagerduty -- failed to ' + @event['action'] + ' incident -- ' + incident_key + ' -- ' +
error.response.code + ' ' + error.response.message + ': ' + error.response.body
if (tries -= 1) > 0
retry
else
puts 'pagerduty -- failed to ' + @event['action'] + ' incident -- ' + incident_key + ' -- ' +
error.response.code + ' ' + error.response.message + ': ' + error.response.body
end
end
end
rescue Timeout::Error
puts 'pagerduty -- timed out while attempting to ' + @event['action'] + ' a incident -- ' + incident_key
if (tries -= 1) > 0
retry
else
puts 'pagerduty -- timed out while attempting to ' + @event['action'] + ' a incident -- ' + incident_key
end
end
end
end

0 comments on commit 4b238ab

Please sign in to comment.