Skip to content

Commit add7638

Browse files
authored
chore: Create FDv2 streaming data source (#349)
1 parent ab7cb79 commit add7638

11 files changed

Lines changed: 708 additions & 24 deletions

File tree

launchdarkly-server-sdk.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Gem::Specification.new do |spec|
4343

4444
spec.add_runtime_dependency "benchmark", "~> 0.1", ">= 0.1.1"
4545
spec.add_runtime_dependency "concurrent-ruby", "~> 1.1"
46-
spec.add_runtime_dependency "ld-eventsource", "2.2.6"
46+
spec.add_runtime_dependency "ld-eventsource", "2.4.0"
4747
spec.add_runtime_dependency "observer", "~> 0.1.2"
4848
spec.add_runtime_dependency "openssl", ">= 3.1.2", "< 5.0"
4949
spec.add_runtime_dependency "semantic", "~> 1.6"

lib/ldclient-rb.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module LaunchDarkly
88
# Public APIs - these define the main interfaces users interact with
99
require "ldclient-rb/config"
1010
require "ldclient-rb/context"
11+
require "ldclient-rb/data_system"
1112
require "ldclient-rb/flags_state"
1213
require "ldclient-rb/integrations"
1314
require "ldclient-rb/interfaces"

lib/ldclient-rb/config.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Config
4545
# @option opts [Hash] :application See {#application}
4646
# @option opts [String] :payload_filter_key See {#payload_filter_key}
4747
# @option opts [Boolean] :omit_anonymous_contexts See {#omit_anonymous_contexts}
48-
# @option opts [DataSystemConfig] :datasystem_config See {#datasystem_config}
48+
# @option opts [DataSystemConfig] :data_system_config See {#data_system_config}
4949
# @option hooks [Array<Interfaces::Hooks::Hook]
5050
# @option plugins [Array<Interfaces::Plugins::Plugin]
5151
#
@@ -84,7 +84,7 @@ def initialize(opts = {})
8484
@hooks = (opts[:hooks] || []).keep_if { |hook| hook.is_a? Interfaces::Hooks::Hook }
8585
@plugins = (opts[:plugins] || []).keep_if { |plugin| plugin.is_a? Interfaces::Plugins::Plugin }
8686
@omit_anonymous_contexts = opts.has_key?(:omit_anonymous_contexts) && opts[:omit_anonymous_contexts]
87-
@datasystem_config = opts[:datasystem_config]
87+
@data_system_config = opts[:data_system_config]
8888
@data_source_update_sink = nil
8989
@instance_id = nil
9090
end
@@ -440,7 +440,7 @@ def diagnostic_opt_out?
440440
#
441441
# @return [DataSystemConfig, nil]
442442
#
443-
attr_reader :datasystem_config
443+
attr_reader :data_system_config
444444

445445

446446
#

lib/ldclient-rb/data_system.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'ldclient-rb/interfaces/data_system'
44
require 'ldclient-rb/config'
55
require 'ldclient-rb/impl/data_system/polling'
6+
require 'ldclient-rb/impl/data_system/streaming'
67

78
module LaunchDarkly
89
#
@@ -132,9 +133,8 @@ def self.fdv1_fallback_ds_builder
132133
# @return [Proc] A proc that takes (sdk_key, config) and returns a streaming data source
133134
#
134135
def self.streaming_ds_builder
135-
# TODO(fdv2): Implement streaming data source builder
136-
lambda do |_sdk_key, _config|
137-
raise NotImplementedError, "Streaming data source not yet implemented for FDv2"
136+
lambda do |sdk_key, config|
137+
LaunchDarkly::Impl::DataSystem::StreamingDataSourceBuilder.new(sdk_key, config).build
138138
end
139139
end
140140

lib/ldclient-rb/impl/data_system/polling.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ def fetch(ss)
9393
#
9494
def sync(ss)
9595
@logger.info { "[LDClient] Starting PollingDataSourceV2 synchronizer" }
96-
@stop.reset
97-
@interrupt_event.reset
9896

9997
until @stop.set?
10098
result = @requester.fetch(ss.selector)
@@ -440,7 +438,7 @@ def self.polling_payload_to_changeset(data)
440438

441439
next unless event[:event]
442440

443-
case event[:event]
441+
case event[:event].to_sym
444442
when LaunchDarkly::Interfaces::DataSystem::EventName::SERVER_INTENT
445443
begin
446444
server_intent = LaunchDarkly::Interfaces::DataSystem::ServerIntent.from_h(event[:data])

lib/ldclient-rb/impl/data_system/protocolv2.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def initialize(version:, kind:, key:)
3939
#
4040
# Returns the event name.
4141
#
42-
# @return [String]
42+
# @return [Symbol]
4343
#
4444
def name
4545
LaunchDarkly::Interfaces::DataSystem::EventName::DELETE_OBJECT
@@ -111,7 +111,7 @@ def initialize(version:, kind:, key:, object:)
111111
#
112112
# Returns the event name.
113113
#
114-
# @return [String]
114+
# @return [Symbol]
115115
#
116116
def name
117117
LaunchDarkly::Interfaces::DataSystem::EventName::PUT_OBJECT

0 commit comments

Comments
 (0)