def httpPost(results, url = @url)
#ensure_cb = Proc.new { |retries| puts "Total Retries: #{retries}" }
exception_cb = Proc.new { |exception| puts "For URL: #{url}\nRetry-rescued error: #{exception.inspect}"}
begin
Retryable.retryable(:exception_cb => exception_cb, tries: 10, sleep: lambda { |n| 4**n }, on: [Errno::ECONNREFUSED, SocketError, Net::ReadTimeout, HTTParty::Error, Timeout::Error, Errno::EPIPE, OpenSSL::SSL::SSLError, EOFError]) do |retries, exception|
response = HTTParty.post(url, body: results.to_json, headers: {'Content-Type' => 'application/json', 'User-Agent' => 'SendGrid 1.0'})
puts "Attempt #{retries} failed with exception: #{exception}" if retries > 0
exception if not [200, 204].include?(response.code) #throw http-code-level error if not a 200 or 204
puts "Total Attempts: #{retries + 1}" if retries > 0
return response
end
rescue StandardError => e
puts "#{Time.now} - httpPost error: #{e.inspect}"
end
end