lib/fluent/plugin/out_newrelic.rb in fluent-plugin-newrelic-0.2.4 vs lib/fluent/plugin/out_newrelic.rb in fluent-plugin-newrelic-0.2.5
- old
+ new
@@ -108,14 +108,25 @@
def was_successful?(response)
200 <= response.code.to_i && response.code.to_i < 300
end
def sleep_duration(attempt)
- [@max_delay, (2 ** attempt) * @retry_seconds].min
+ if attempt == 0
+ return 0
+ end
+
+ [@max_delay, (2 ** (attempt - 1)) * @retry_seconds].min
end
+ def sleep_on_retry(attempt)
+ duration = sleep_duration(attempt)
+ if duration > 0
+ sleep duration
+ end
+ end
+
def attempt_send(payload, attempt)
- sleep sleep_duration(attempt)
+ sleep_on_retry(attempt)
attempt_send(payload, attempt + 1) unless was_successful?(send(payload)) if should_retry?(attempt)
end
def send(payload)
http = Net::HTTP.new(@end_point.host, 443)