34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/ldclient-rb/polling.rb', line 34
def poll
begin
all_data = @requestor.request_all_data
if all_data
update_sink_or_data_store.init(all_data)
if @initialized.make_true
@config.logger.info { "[LDClient] Polling connection initialized" }
@ready.set
end
end
@config.data_source_update_sink&.update_status(LaunchDarkly::Interfaces::DataSource::Status::VALID, nil)
rescue JSON::ParserError => e
@config.logger.error { "[LDClient] JSON parsing failed for polling response." }
error_info = LaunchDarkly::Interfaces::DataSource::ErrorInfo.new(
LaunchDarkly::Interfaces::DataSource::ErrorInfo::INVALID_DATA,
0,
e.to_s,
Time.now
)
@config.data_source_update_sink&.update_status(LaunchDarkly::Interfaces::DataSource::Status::INTERRUPTED, error_info)
rescue UnexpectedResponseError => e
error_info = LaunchDarkly::Interfaces::DataSource::ErrorInfo.new(
LaunchDarkly::Interfaces::DataSource::ErrorInfo::ERROR_RESPONSE, e.status, nil, Time.now)
message = Util.http_error_message(e.status, "polling request", "will retry")
@config.logger.error { "[LDClient] #{message}" }
if Util.http_error_recoverable?(e.status)
@config.data_source_update_sink&.update_status(
LaunchDarkly::Interfaces::DataSource::Status::INTERRUPTED,
error_info
)
else
@ready.set stop_with_error_info error_info
end
rescue StandardError => e
Util.log_exception(@config.logger, "Exception while polling", e)
@config.data_source_update_sink&.update_status(
LaunchDarkly::Interfaces::DataSource::Status::INTERRUPTED,
LaunchDarkly::Interfaces::DataSource::ErrorInfo.new(LaunchDarkly::Interfaces::DataSource::ErrorInfo::UNKNOWN, 0, e.to_s, Time.now)
)
end
end
|