cf_light_api 1.0.0 → 1.1.0
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 +48 -21
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 417316fd53dc02ae75d5173f4476810f1d859e20
|
4
|
+
data.tar.gz: 2352be1e3ef38ca27cfe76ce335d8da94f242976
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e140e367cfe2ca04c18fca383102e80fd26c54255da38477703157dd360ad444d58401b138bdb3150c0719b87b0cac7247fd1bd02e8cdbdaef4b645daf19809f
|
7
|
+
data.tar.gz: 2e253d06021d0b874d5d150d2e76d2b775b11ec9eef3cf3d0de38aa05527f62035a12c106af07e1a1fa5a40558f61b18df7f92a6a4be02f425519a63008fb643
|
data/lib/cf_light_api/worker.rb
CHANGED
@@ -8,34 +8,61 @@ require 'rufus-scheduler'
|
|
8
8
|
end
|
9
9
|
|
10
10
|
scheduler = Rufus::Scheduler.new
|
11
|
-
scheduler.every '5m', :first_in => '5s', :overlap => false do
|
11
|
+
scheduler.every '5m', :first_in => '5s', :overlap => false, :timeout => '15m' do
|
12
|
+
begin
|
13
|
+
if locked?
|
14
|
+
puts "[cf_light_api:worker] Data update is already running in another worker, skipping..."
|
15
|
+
next
|
16
|
+
end
|
12
17
|
|
13
|
-
|
18
|
+
lock
|
14
19
|
|
15
|
-
|
20
|
+
puts "[cf_light_api:worker] Updating data..."
|
16
21
|
|
17
|
-
|
18
|
-
app_data = []
|
19
|
-
cf_client.organizations.each do |org|
|
20
|
-
# The CFoundry client returns memory_limit in MB, so we need to normalise to Bytes to match the Apps.
|
22
|
+
cf_client = get_client()
|
21
23
|
|
22
|
-
org_data
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
org_data = []
|
25
|
+
app_data = []
|
26
|
+
cf_client.organizations.each do |org|
|
27
|
+
# The CFoundry client returns memory_limit in MB, so we need to normalise to Bytes to match the Apps.
|
28
|
+
org_data << {
|
29
|
+
:name => org.name,
|
30
|
+
:quota => {
|
31
|
+
:total_services => org.quota_definition.total_services,
|
32
|
+
:memory_limit => org.quota_definition.memory_limit * 1024 * 1024
|
33
|
+
}
|
27
34
|
}
|
28
|
-
}
|
29
35
|
|
30
|
-
|
31
|
-
|
32
|
-
|
36
|
+
org.spaces.each do |space|
|
37
|
+
puts "processing space #{space.name}..."
|
38
|
+
space.apps.each do |app|
|
39
|
+
puts "processing app #{app.name}..."
|
40
|
+
app_data << format_app_data(app, org.name, space.name)
|
41
|
+
end
|
33
42
|
end
|
34
43
|
end
|
44
|
+
|
45
|
+
unlock
|
46
|
+
|
47
|
+
put_in_redis "#{ENV['REDIS_KEY_PREFIX']}:orgs", org_data
|
48
|
+
put_in_redis "#{ENV['REDIS_KEY_PREFIX']}:apps", app_data
|
49
|
+
|
50
|
+
rescue Rufus::Scheduler::TimeoutError
|
51
|
+
puts '[cf_light_api:worker] Data update took too long and was aborted...'
|
35
52
|
end
|
36
|
-
|
37
|
-
|
53
|
+
end
|
54
|
+
|
55
|
+
def locked?
|
56
|
+
REDIS.get("#{ENV['REDIS_KEY_PREFIX']}:lock") ? true : false
|
57
|
+
end
|
58
|
+
|
59
|
+
def lock
|
60
|
+
REDIS.set "#{ENV['REDIS_KEY_PREFIX']}:lock", true
|
61
|
+
REDIS.expire "#{ENV['REDIS_KEY_PREFIX']}:lock", 900
|
62
|
+
end
|
38
63
|
|
64
|
+
def unlock
|
65
|
+
REDIS.del "#{ENV['REDIS_KEY_PREFIX']}:lock"
|
39
66
|
end
|
40
67
|
|
41
68
|
def get_client(cf_api=ENV['CF_API'], cf_user=ENV['CF_USER'], cf_password=ENV['CF_PASSWORD'])
|
@@ -57,9 +84,9 @@ def format_app_data(app, org_name, space_name)
|
|
57
84
|
additional_data = {}
|
58
85
|
begin
|
59
86
|
additional_data = {
|
60
|
-
|
61
|
-
|
62
|
-
|
87
|
+
:running => app.running?,
|
88
|
+
:instances => app.running? ? app.stats.map{|key, value| value} : [],
|
89
|
+
:error => nil
|
63
90
|
}
|
64
91
|
rescue => e
|
65
92
|
puts "[cf_light_api:worker] #{org_name} #{space_name}: '#{app.name}'' error: #{e.message}"
|
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: 1.
|
4
|
+
version: 1.1.0
|
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: 2015-03-
|
11
|
+
date: 2015-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cfoundry
|
@@ -78,7 +78,7 @@ files:
|
|
78
78
|
- ./lib/cf_light_api/redis.rb
|
79
79
|
- ./lib/cf_light_api/worker.rb
|
80
80
|
- bin/cf_light_api
|
81
|
-
homepage:
|
81
|
+
homepage: https://github.com/springerpe/cf-light-api
|
82
82
|
licenses:
|
83
83
|
- MIT
|
84
84
|
metadata: {}
|