ldclient-rb 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d3b7afae59606e6cf63711b7ebce25fb00ab2ca
4
- data.tar.gz: e6118509c561eb65351ad2d7dfe6b72972ca7537
3
+ metadata.gz: bb529ae4cee84dc59dc337679aefcc43c30387f1
4
+ data.tar.gz: 289912147c41778bda0bfe4782c79c0c5aa1db49
5
5
  SHA512:
6
- metadata.gz: a4a52b5b3ca9ad33c0fce7bb68b1bb465a1e41899331175b1d8c979ac14d75ae5e1b5e6ac3a15006db3b77b95d1c3aabfcb2799b52c042e53e2bcc4940a75645
7
- data.tar.gz: 0a2a5c1e2eb0cbb268f4f4db64e39f0c72ea7371640346b3c5954bdfd523d013f189ab25bb79b2cbbc73cd31e30706495624ef2ae50766641e40a623ef5ca11c
6
+ metadata.gz: b2c63e0292ad05fba2a4751f70f900816a4fac97d73d8dcb81602465aa461c1fa08df5cfbb0fecff659a9827c22c07d57f36be63053845f13a3f0c13aaea11dc
7
+ data.tar.gz: f1379084fc8edc81b3355b68fb8eb17b5ab31f39fda1b37ba1a4052f3cfa157c956924950a8c0275f1fc621957c544c795308e994c641036c8e7cd36ff7b7df0
@@ -20,7 +20,7 @@ module LaunchDarkly
20
20
  #
21
21
  # @return [type] [description]
22
22
  def initialize(opts = {})
23
- @base_uri = opts[:base_uri] || Config.default_base_uri
23
+ @base_uri = (opts[:base_uri] || Config.default_base_uri).chomp("/")
24
24
  @capacity = opts[:capacity] || Config.default_capacity
25
25
  @logger = opts[:logger] || Config.default_logger
26
26
  @store = opts[:store] || Config.default_store
@@ -91,7 +91,7 @@ module LaunchDarkly
91
91
  end
92
92
 
93
93
  def self.default_flush_interval
94
- 30
94
+ 10
95
95
  end
96
96
 
97
97
  def self.default_logger
@@ -32,31 +32,38 @@ module LaunchDarkly
32
32
  builder.adapter Faraday.default_adapter
33
33
  end
34
34
 
35
+ @worker = create_worker()
36
+ end
37
+
38
+ def create_worker()
35
39
  Thread.new do
36
40
  while true do
37
- events = []
38
- num_events = @queue.length()
39
- num_events.times do
40
- events << @queue.pop()
41
- end
42
-
43
- if !events.empty?()
44
- res =
45
- @client.post (@config.base_uri + "/api/events/bulk") do |req|
46
- req.headers['Authorization'] = 'api_key ' + @api_key
47
- req.headers['User-Agent'] = 'RubyClient/' + LaunchDarkly::VERSION
48
- req.headers['Content-Type'] = 'application/json'
49
- req.body = events.to_json
41
+ begin
42
+ events = []
43
+ num_events = @queue.length()
44
+ num_events.times do
45
+ events << @queue.pop()
50
46
  end
51
- if res.status != 200
52
- @config.logger.error("Unexpected status code while processing events: " + res.status)
47
+
48
+ if !events.empty?()
49
+ res =
50
+ @client.post (@config.base_uri + "/api/events/bulk") do |req|
51
+ req.headers['Authorization'] = 'api_key ' + @api_key
52
+ req.headers['User-Agent'] = 'RubyClient/' + LaunchDarkly::VERSION
53
+ req.headers['Content-Type'] = 'application/json'
54
+ req.body = events.to_json
55
+ end
56
+ if res.status != 200
57
+ @config.logger.error("[LDClient] Unexpected status code while processing events: #{res.status}")
58
+ end
53
59
  end
54
- end
55
60
 
56
- sleep(@config.flush_interval)
61
+ sleep(@config.flush_interval)
62
+ rescue Exception => exn
63
+ @config.logger.error("[LDClient] Unexpected exception in create_worker: #{exn.message}")
64
+ end
57
65
  end
58
66
  end
59
-
60
67
  end
61
68
 
62
69
  #
@@ -95,7 +102,7 @@ module LaunchDarkly
95
102
  add_event({:kind => 'feature', :key => key, :user => user, :value => value})
96
103
  return value
97
104
  rescue StandardError => error
98
- @config.logger.error("Unhandled exception in get_flag: " + error.message)
105
+ @config.logger.error("[LDClient] Unhandled exception in get_flag: #{error.message}")
99
106
  default
100
107
  end
101
108
  end
@@ -104,8 +111,12 @@ module LaunchDarkly
104
111
  if @queue.length() < @config.capacity
105
112
  event[:creationDate] = (Time.now.to_f * 1000).to_i
106
113
  @queue.push(event)
114
+
115
+ if ! @worker.alive?
116
+ @worker = create_worker()
117
+ end
107
118
  else
108
- @config.logger.warn("Exceeded event queue capacity. Increase capacity to avoid dropping events.")
119
+ @config.logger.warn("[LDClient] Exceeded event queue capacity. Increase capacity to avoid dropping events.")
109
120
  end
110
121
  end
111
122
 
@@ -124,7 +135,7 @@ module LaunchDarkly
124
135
  def get_flag_int(key, user, default)
125
136
 
126
137
  unless user
127
- @config.logger.error("Must specify user")
138
+ @config.logger.error("[LDClient] Must specify user")
128
139
  return default
129
140
  end
130
141
 
@@ -135,17 +146,17 @@ module LaunchDarkly
135
146
  end
136
147
 
137
148
  if res.status == 401
138
- @config.logger.error("Invalid API key")
149
+ @config.logger.error("[LDClient] Invalid API key")
139
150
  return default
140
151
  end
141
152
 
142
153
  if res.status == 404
143
- @config.logger.error("Unknown feature key: " + key)
154
+ @config.logger.error("[LDClient] Unknown feature key: #{key}")
144
155
  return default
145
156
  end
146
157
 
147
158
  if res.status != 200
148
- @config.logger.error("Unexpected status code " + res.status)
159
+ @config.logger.error("[LDClient] Unexpected status code #{res.status}")
149
160
  return default
150
161
  end
151
162
 
@@ -242,7 +253,7 @@ module LaunchDarkly
242
253
 
243
254
  end
244
255
 
245
- private :add_event, :get_flag_int, :param_for_user, :match_target?, :match_variation?, :evaluate
256
+ private :add_event, :get_flag_int, :param_for_user, :match_target?, :match_variation?, :evaluate, :create_worker
246
257
 
247
258
 
248
259
  end
@@ -1,3 +1,3 @@
1
1
  module LaunchDarkly
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ldclient-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Catamorphic Co
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-17 00:00:00.000000000 Z
11
+ date: 2014-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler