...
1 package ldcomponents
2
3 import (
4 "time"
5
6 "github.com/launchdarkly/go-sdk-common/v3/ldvalue"
7 "github.com/launchdarkly/go-server-sdk/v6/internal/datasource"
8 "github.com/launchdarkly/go-server-sdk/v6/internal/endpoints"
9 "github.com/launchdarkly/go-server-sdk/v6/subsystems"
10 )
11
12
13 const DefaultPollingBaseURI = "https://app.launchdarkly.com"
14
15
16 const DefaultPollInterval = 30 * time.Second
17
18
19
20
21 type PollingDataSourceBuilder struct {
22 baseURI string
23 pollInterval time.Duration
24 }
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 func PollingDataSource() *PollingDataSourceBuilder {
41 return &PollingDataSourceBuilder{
42 pollInterval: DefaultPollInterval,
43 }
44 }
45
46
47
48
49 func (b *PollingDataSourceBuilder) PollInterval(pollInterval time.Duration) *PollingDataSourceBuilder {
50 if pollInterval < DefaultPollInterval {
51 b.pollInterval = DefaultPollInterval
52 } else {
53 b.pollInterval = pollInterval
54 }
55 return b
56 }
57
58
59
60
61 func (b *PollingDataSourceBuilder) forcePollInterval(
62 pollInterval time.Duration,
63 ) *PollingDataSourceBuilder {
64 b.pollInterval = pollInterval
65 return b
66 }
67
68
69 func (b *PollingDataSourceBuilder) Build(context subsystems.ClientContext) (subsystems.DataSource, error) {
70 context.GetLogging().Loggers.Warn(
71 "You should only disable the streaming API if instructed to do so by LaunchDarkly support")
72 configuredBaseURI := endpoints.SelectBaseURI(
73 context.GetServiceEndpoints(),
74 endpoints.PollingService,
75 b.baseURI,
76 context.GetLogging().Loggers,
77 )
78 pp := datasource.NewPollingProcessor(context, context.GetDataSourceUpdateSink(), configuredBaseURI, b.pollInterval)
79 return pp, nil
80 }
81
82
83 func (b *PollingDataSourceBuilder) DescribeConfiguration(context subsystems.ClientContext) ldvalue.Value {
84 return ldvalue.ObjectBuild().
85 SetBool("streamingDisabled", true).
86 SetBool("customBaseURI",
87 endpoints.IsCustom(context.GetServiceEndpoints(), endpoints.PollingService, b.baseURI)).
88 Set("pollingIntervalMillis", durationToMillisValue(b.pollInterval)).
89 SetBool("usingRelayDaemon", false).
90 Build()
91 }
92
View as plain text