cf_light_api 2.5.1 → 2.6.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cf_light_api/worker.rb +21 -5
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0aa34192c2cb28dd5d9264bf8a9f20dbc4c11f0e
|
4
|
+
data.tar.gz: d3cbeddf6a787d949749485c9a9a78d61a05b467
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddd3c48ecdb5ce722b349d528fe886399bf30fa370560ce84c0f0cadcc4e116d62c2afb099e861f1aa8d0bf3fe8a54e11d19f52eb629f001198bccb4285bf928
|
7
|
+
data.tar.gz: fc3b794eff7f955015c6f51991ed1d7b013fcbe399b37f895b3ed350980b5414cf57c61e28d16ed930aab7a629ced1be09edfc04e2ddb132ba1484ed104fe45e
|
data/lib/cf_light_api/worker.rb
CHANGED
@@ -5,6 +5,7 @@ require 'redlock'
|
|
5
5
|
require 'logger'
|
6
6
|
require 'graphite-api'
|
7
7
|
require 'date'
|
8
|
+
require 'parallel'
|
8
9
|
|
9
10
|
class CFLightAPIWorker
|
10
11
|
if ENV['NEW_RELIC_LICENSE_KEY']
|
@@ -42,11 +43,14 @@ class CFLightAPIWorker
|
|
42
43
|
update_interval = (ENV['UPDATE_INTERVAL'] || '5m').to_s # If you change the default '5m' here, also remember to change the default age validity in sinatra/cf_light_api.rb:31
|
43
44
|
update_timeout = (ENV['UPDATE_TIMEOUT'] || '5m').to_s
|
44
45
|
|
46
|
+
@update_threads = (ENV['UPDATE_THREADS'] || 1).to_i
|
47
|
+
|
45
48
|
@lock_manager = Redlock::Client.new([ENV['REDIS_URI']])
|
46
49
|
@scheduler = Rufus::Scheduler.new
|
47
50
|
|
48
|
-
@logger.info "Update interval: '#{
|
49
|
-
@logger.info "Update timeout: '#{
|
51
|
+
@logger.info "Update interval: '#{update_interval}'"
|
52
|
+
@logger.info "Update timeout: '#{update_timeout}'"
|
53
|
+
@logger.info "Update threads: '#{@update_threads}'"
|
50
54
|
|
51
55
|
if ENV['GRAPHITE_HOST'] and ENV['GRAPHITE_PORT']
|
52
56
|
@logger.info "Graphite server: #{ENV['GRAPHITE_HOST']}:#{ENV['GRAPHITE_PORT']}"
|
@@ -119,6 +123,12 @@ class CFLightAPIWorker
|
|
119
123
|
end
|
120
124
|
end
|
121
125
|
|
126
|
+
def send_cf_light_api_update_time_to_graphite seconds
|
127
|
+
graphite_key = "cf_light_api.#{ENV['CF_ENV_NAME']}.update_duration"
|
128
|
+
@logger.info "Exporting CF Light API update time to Graphite, path '#{graphite_key}'=>'#{seconds.round}'"
|
129
|
+
@graphite.metrics "#{graphite_base}" => seconds.round
|
130
|
+
end
|
131
|
+
|
122
132
|
def put_in_redis(key, data)
|
123
133
|
REDIS.set key, data.to_json
|
124
134
|
end
|
@@ -196,7 +206,7 @@ class CFLightAPIWorker
|
|
196
206
|
}
|
197
207
|
end
|
198
208
|
|
199
|
-
formatted_apps = @apps
|
209
|
+
formatted_apps = Parallel.map(@apps, :in_threads => @update_threads) do |app|
|
200
210
|
# TODO: This is a bit repetative, could maybe improve?
|
201
211
|
space = @spaces.find{|a_space| a_space['metadata']['guid'] == app['entity']['space_guid']}
|
202
212
|
org = @orgs.find{|an_org| an_org['metadata']['guid'] == space['entity']['organization_guid']}
|
@@ -247,7 +257,9 @@ class CFLightAPIWorker
|
|
247
257
|
:error => nil
|
248
258
|
}
|
249
259
|
|
250
|
-
rescue => e
|
260
|
+
rescue Rufus::Scheduler::TimeoutError => e
|
261
|
+
raise e
|
262
|
+
rescue StandardError => e
|
251
263
|
# Most exceptions here will be caused by the app or one of the instances being in a non-standard state,
|
252
264
|
# for example, trying to query an app which was present when the worker began updating, but was stopped
|
253
265
|
# before we reached this section, so we just catch all exceptions, log the reason and move on.
|
@@ -268,7 +280,10 @@ class CFLightAPIWorker
|
|
268
280
|
put_in_redis "#{ENV['REDIS_KEY_PREFIX']}:apps", formatted_apps
|
269
281
|
put_in_redis "#{ENV['REDIS_KEY_PREFIX']}:last_updated", {:last_updated => Time.now}
|
270
282
|
|
271
|
-
|
283
|
+
elapsed_seconds = Time.now.to_f - start_time.to_f
|
284
|
+
@logger.info "Update completed in #{format_duration(elapsed_seconds)}..."
|
285
|
+
send_cf_light_api_update_time_to_graphite(elapsed_seconds) if @graphite
|
286
|
+
|
272
287
|
@lock_manager.unlock(lock)
|
273
288
|
@cf_client.logout
|
274
289
|
else
|
@@ -277,6 +292,7 @@ class CFLightAPIWorker
|
|
277
292
|
end
|
278
293
|
rescue Rufus::Scheduler::TimeoutError
|
279
294
|
@logger.info 'Data update took too long and was aborted, waiting for the lock to expire before trying again...'
|
295
|
+
send_cf_light_api_update_time_to_graphite(0) if @graphite
|
280
296
|
@cf_client.logout
|
281
297
|
end
|
282
298
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cf_light_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0.pre1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Springer Platform Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cfoundry
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 3.17.1
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: parallel
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.12.0
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.12.0
|
111
125
|
description: A super lightweight API for reading App and Org data from CloudFoundry,
|
112
126
|
cached in Redis.
|
113
127
|
email: ''
|
@@ -135,9 +149,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
135
149
|
version: '0'
|
136
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
151
|
requirements:
|
138
|
-
- - "
|
152
|
+
- - ">"
|
139
153
|
- !ruby/object:Gem::Version
|
140
|
-
version:
|
154
|
+
version: 1.3.1
|
141
155
|
requirements: []
|
142
156
|
rubyforge_project:
|
143
157
|
rubygems_version: 2.5.1
|