Skip to content

Commit

Permalink
Provide default values for flush interval. (#62)
Browse files Browse the repository at this point in the history
Event relay would panic with a default value of 0.
  • Loading branch information
ashanbrown authored Aug 4, 2018
1 parent 607d1af commit 79f6d77
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
11 changes: 8 additions & 3 deletions internal/events/event-relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,16 @@ func NewEventRelayHandler(sdkKey string, config Config, featureStore ld.FeatureS
}

func newEventVerbatimRelay(sdkKey string, config Config) *eventVerbatimRelay {
publisher, _ := NewHttpEventPublisher(sdkKey,
opts := []OptionType{
OptionCapacity(config.Capacity),
OptionUri(config.EventsUri),
OptionFlushInterval(time.Duration(config.FlushIntervalSecs)*time.Second),
)
}

if config.FlushIntervalSecs > 0 {
opts = append(opts, OptionFlushInterval(time.Duration(config.FlushIntervalSecs)*time.Second))
}

publisher, _ := NewHttpEventPublisher(sdkKey, opts...)

res := &eventVerbatimRelay{
config: config,
Expand Down
4 changes: 3 additions & 1 deletion internal/events/event_publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ func NewHttpEventPublisher(sdkKey string, options ...OptionType) (*HttpEventPubl
}
switch o := o.(type) {
case OptionFlushInterval:
flushInterval = time.Duration(o)
if o > 0 {
flushInterval = time.Duration(o)
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (
defaultStreamUri = "https://stream.launchdarkly.com/"
defaultHeartbeatIntervalSecs = 180
defaultMetricsPrefix = "launchdarkly_relay"
defaultFlushIntervalSecs = 5

userAgentHeader = "user-agent"
)
Expand Down Expand Up @@ -186,6 +187,7 @@ func init() {
DefaultConfig.Main.HeartbeatIntervalSecs = defaultHeartbeatIntervalSecs
DefaultConfig.Main.Port = defaultPort
DefaultConfig.Redis.LocalTtl = defaultRedisLocalTtlMs
DefaultConfig.Events.FlushIntervalSecs = defaultFlushIntervalSecs
}

// LoadConfigFile reads a config file into a Config struct
Expand Down

0 comments on commit 79f6d77

Please sign in to comment.