Skip to content

Commit b0a19b5

Browse files
committed
split out the interface file that is getting too large
1 parent 9abdd64 commit b0a19b5

File tree

9 files changed

+1131
-1106
lines changed

9 files changed

+1131
-1106
lines changed

lib/ldclient-rb/interfaces.rb

Lines changed: 8 additions & 1106 deletions
Large diffs are not rendered by default.
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
require "observer"
2+
3+
module LaunchDarkly
4+
module Interfaces
5+
module BigSegmentStore
6+
#
7+
# Returns information about the overall state of the store. This method will be called only
8+
# when the SDK needs the latest state, so it should not be cached.
9+
#
10+
# @return [BigSegmentStoreMetadata]
11+
#
12+
def get_metadata
13+
end
14+
15+
#
16+
# Queries the store for a snapshot of the current segment state for a specific context.
17+
#
18+
# The context_hash is a base64-encoded string produced by hashing the context key as defined by
19+
# the Big Segments specification; the store implementation does not need to know the details
20+
# of how this is done, because it deals only with already-hashed keys, but the string can be
21+
# assumed to only contain characters that are valid in base64.
22+
#
23+
# The return value should be either a Hash, or nil if the context is not referenced in any big
24+
# segments. Each key in the Hash is a "segment reference", which is how segments are
25+
# identified in Big Segment data. This string is not identical to the segment key-- the SDK
26+
# will add other information. The store implementation should not be concerned with the
27+
# format of the string. Each value in the Hash is true if the context is explicitly included in
28+
# the segment, false if the context is explicitly excluded from the segment-- and is not also
29+
# explicitly included (that is, if both an include and an exclude existed in the data, the
30+
# include would take precedence). If the context's status in a particular segment is undefined,
31+
# there should be no key or value for that segment.
32+
#
33+
# This Hash may be cached by the SDK, so it should not be modified after it is created. It
34+
# is a snapshot of the segment membership state at one point in time.
35+
#
36+
# @param context_hash [String]
37+
# @return [Hash] true/false values for Big Segments that reference this context
38+
#
39+
def get_membership(context_hash)
40+
end
41+
42+
#
43+
# Performs any necessary cleanup to shut down the store when the client is being shut down.
44+
#
45+
# @return [void]
46+
#
47+
def stop
48+
end
49+
end
50+
51+
#
52+
# Values returned by {BigSegmentStore#get_metadata}.
53+
#
54+
class BigSegmentStoreMetadata
55+
def initialize(last_up_to_date)
56+
@last_up_to_date = last_up_to_date
57+
end
58+
59+
# The Unix epoch millisecond timestamp of the last update to the {BigSegmentStore}. It is
60+
# nil if the store has never been updated.
61+
#
62+
# @return [Integer|nil]
63+
attr_reader :last_up_to_date
64+
end
65+
66+
#
67+
# Information about the status of a Big Segment store, provided by {BigSegmentStoreStatusProvider}.
68+
#
69+
# Big Segments are a specific type of segments. For more information, read the LaunchDarkly
70+
# documentation: https://docs.launchdarkly.com/home/users/big-segments
71+
#
72+
class BigSegmentStoreStatus
73+
def initialize(available, stale)
74+
@available = available
75+
@stale = stale
76+
end
77+
78+
# True if the Big Segment store is able to respond to queries, so that the SDK can evaluate
79+
# whether a context is in a segment or not.
80+
#
81+
# If this property is false, the store is not able to make queries (for instance, it may not have
82+
# a valid database connection). In this case, the SDK will treat any reference to a Big Segment
83+
# as if no contexts are included in that segment. Also, the {EvaluationReason} associated with
84+
# with any flag evaluation that references a Big Segment when the store is not available will
85+
# have a `big_segments_status` of `STORE_ERROR`.
86+
#
87+
# @return [Boolean]
88+
attr_reader :available
89+
90+
# True if the Big Segment store is available, but has not been updated within the amount of time
91+
# specified by {BigSegmentsConfig#stale_after}.
92+
#
93+
# This may indicate that the LaunchDarkly Relay Proxy, which populates the store, has stopped
94+
# running or has become unable to receive fresh data from LaunchDarkly. Any feature flag
95+
# evaluations that reference a Big Segment will be using the last known data, which may be out
96+
# of date. Also, the {EvaluationReason} associated with those evaluations will have a
97+
# `big_segments_status` of `STALE`.
98+
#
99+
# @return [Boolean]
100+
attr_reader :stale
101+
102+
def ==(other)
103+
self.available == other.available && self.stale == other.stale
104+
end
105+
end
106+
107+
#
108+
# An interface for querying the status of a Big Segment store.
109+
#
110+
# The Big Segment store is the component that receives information about Big Segments, normally
111+
# from a database populated by the LaunchDarkly Relay Proxy. Big Segments are a specific type
112+
# of segments. For more information, read the LaunchDarkly documentation:
113+
# https://docs.launchdarkly.com/home/users/big-segments
114+
#
115+
# An implementation of this interface is returned by {LDClient#big_segment_store_status_provider}.
116+
# Application code never needs to implement this interface.
117+
#
118+
# There are two ways to interact with the status. One is to simply get the current status; if its
119+
# `available` property is true, then the SDK is able to evaluate context membership in Big Segments,
120+
# and the `stale`` property indicates whether the data might be out of date.
121+
#
122+
# The other way is to subscribe to status change notifications. Applications may wish to know if
123+
# there is an outage in the Big Segment store, or if it has become stale (the Relay Proxy has
124+
# stopped updating it with new data), since then flag evaluations that reference a Big Segment
125+
# might return incorrect values. To allow finding out about status changes as soon as possible,
126+
# `BigSegmentStoreStatusProvider` mixes in Ruby's
127+
# [Observable](https://docs.ruby-lang.org/en/2.5.0/Observable.html) module to provide standard
128+
# methods such as `add_observer`. Observers will be called with a new {BigSegmentStoreStatus}
129+
# value whenever the status changes.
130+
#
131+
# @example Getting the current status
132+
# status = client.big_segment_store_status_provider.status
133+
#
134+
# @example Subscribing to status notifications
135+
# client.big_segment_store_status_provider.add_observer(self, :big_segments_status_changed)
136+
#
137+
# def big_segments_status_changed(new_status)
138+
# puts "Big segment store status is now: #{new_status}"
139+
# end
140+
#
141+
module BigSegmentStoreStatusProvider
142+
include Observable
143+
#
144+
# Gets the current status of the store, if known.
145+
#
146+
# @return [BigSegmentStoreStatus] the status, or nil if the SDK has not yet queried the Big
147+
# Segment store status
148+
#
149+
def status
150+
end
151+
end
152+
end
153+
end

0 commit comments

Comments
 (0)