294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
# File 'lib/ldclient-rb/events.rb', line 294
def run(sdk_key, config, client, payload, formatter)
events_out = formatter.make_output_events(payload.events, payload.summary)
res = nil
body = events_out.to_json
(0..1).each do |attempt|
if attempt > 0
config.logger.warn { "[LDClient] Will retry posting events after 1 second" }
sleep(1)
end
begin
config.logger.debug { "[LDClient] sending #{events_out.length} events: #{body}" }
res = client.post (config.events_uri + "/bulk") do |req|
req.["Authorization"] = sdk_key
req.["User-Agent"] = "RubyClient/" + LaunchDarkly::VERSION
req.["Content-Type"] = "application/json"
req.["X-LaunchDarkly-Event-Schema"] = CURRENT_SCHEMA_VERSION.to_s
req.body = body
req.options.timeout = config.read_timeout
req.options.open_timeout = config.connect_timeout
end
rescue StandardError => exn
config.logger.warn { "[LDClient] Error flushing events: #{exn.inspect}." }
next
end
if res.status < 200 || res.status >= 300
if Util.http_error_recoverable?(res.status)
next
end
end
break
end
res
end
|