web47core 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/status_controller.rb +68 -21
- data/app/helpers/core_helper.rb +0 -4
- data/app/views/status/index.html.haml +1 -1
- data/lib/web47core/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0df839ec2a6e7d78c8ef4e250179643a359e0b5723b35992ab4dfda76ccd1886
|
4
|
+
data.tar.gz: 31b961889cc2bf8748da8b2ea26d050a20fed870adfdcc68a5e8bce1f0e67409
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fe114893789eee1c74a7f0c8870c4669feb38d8d67010b9425634b20910c7bce0bbd5825c3f0fe3e65eb4f58fabf8c49b390b868fa6f0c8bb8ee3821fcf7c4d
|
7
|
+
data.tar.gz: ba5626fdb74f667f55c992d84253026e8a50679552d7c4447d3832cfcbe05bbe26e84c4900ed23159a7cdc873149b6769e6d27aee559312f1aeedcfb0dcfc26f
|
@@ -4,36 +4,62 @@
|
|
4
4
|
# Return the status of the server
|
5
5
|
#
|
6
6
|
class StatusController < ActionController::Base
|
7
|
+
protect_from_forgery with: :exception
|
7
8
|
#
|
8
9
|
# Main (and only) page
|
9
10
|
#
|
10
11
|
def index
|
11
|
-
components = { mongo: mongo_status,
|
12
|
+
components = { mongo: mongo_status,
|
13
|
+
redis: redis_status,
|
14
|
+
jobs: delayed_jobs_status,
|
15
|
+
cron_job_servers: cron_job_servers_status,
|
16
|
+
workers: workers_status }
|
12
17
|
|
13
18
|
respond_to do |format|
|
14
|
-
format.html { render :index, locals: { components: components }, layout: false }
|
19
|
+
format.html { render :index, locals: { components: ui_decorators(components) }, layout: false }
|
15
20
|
format.json { render json: components.to_json }
|
16
|
-
format.text
|
17
|
-
overall = components.collect { |_key, item| item[:success] }.all?
|
18
|
-
render plain: components.flatten, status: overall ? 200 : 500
|
19
|
-
end
|
21
|
+
format.text { render plain: components.flatten, status: text_status(components) }
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
25
|
private
|
24
26
|
|
27
|
+
#
|
28
|
+
# Return the status of the key components, mongo, redis
|
29
|
+
#
|
30
|
+
def text_status(components)
|
31
|
+
components[:mongo][:success] && components[:redis][:success] ? 200 : 500
|
32
|
+
rescue StandardError
|
33
|
+
500
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# Add UI decorators for HTML formatting
|
38
|
+
#
|
39
|
+
def ui_decorators(components)
|
40
|
+
components.each do |key, values|
|
41
|
+
if values[:success]
|
42
|
+
components[key][:icon_name] = 'check_circle'
|
43
|
+
components[key][:icon_color] = 'green-text'
|
44
|
+
else
|
45
|
+
components[key][:icon_name] = 'error'
|
46
|
+
components[key][:icon_color] = 'red-text'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
25
51
|
#
|
26
52
|
# Report an error for the check
|
27
53
|
#
|
28
|
-
def report_error(error)
|
29
|
-
|
54
|
+
def report_error(error, metrics = {})
|
55
|
+
metrics.merge(success: false, message: error.message)
|
30
56
|
end
|
31
57
|
|
32
58
|
#
|
33
59
|
# Report a success for the check
|
34
60
|
#
|
35
|
-
def report_success(message)
|
36
|
-
|
61
|
+
def report_success(message, metrics = {})
|
62
|
+
metrics.merge(success: true, message: message)
|
37
63
|
end
|
38
64
|
|
39
65
|
#
|
@@ -42,9 +68,9 @@ class StatusController < ActionController::Base
|
|
42
68
|
def mongo_status
|
43
69
|
raise 'Mongo not available' if SystemConfiguration.count.zero?
|
44
70
|
|
45
|
-
report_success "#{SystemConfiguration.count} Configs"
|
71
|
+
report_success "#{SystemConfiguration.count} Configs", count: SystemConfiguration.count
|
46
72
|
rescue StandardError => error
|
47
|
-
report_error
|
73
|
+
report_error error, count: 0
|
48
74
|
end
|
49
75
|
|
50
76
|
#
|
@@ -55,32 +81,53 @@ class StatusController < ActionController::Base
|
|
55
81
|
Rails.cache.write 'redis-status-check', value
|
56
82
|
raise 'Redis not available' unless value.eql?(Rails.cache.fetch('redis-status-check'))
|
57
83
|
|
58
|
-
report_success 'Redis Available'
|
84
|
+
report_success 'Redis Available', count: 1
|
59
85
|
rescue StandardError => error
|
60
|
-
report_error(error)
|
86
|
+
report_error(error, count: 0)
|
61
87
|
end
|
62
88
|
|
63
89
|
#
|
64
90
|
# Job Count
|
65
91
|
#
|
66
|
-
def
|
67
|
-
|
92
|
+
def delayed_jobs_status
|
93
|
+
count = Delayed::Backend::Mongoid::Job.count
|
94
|
+
report_success "#{count} Jobs", count: count
|
68
95
|
rescue StandardError => error
|
69
96
|
report_error(error)
|
70
97
|
end
|
71
98
|
|
72
99
|
#
|
73
|
-
# Cron job status
|
100
|
+
# Cron job primary status
|
74
101
|
#
|
75
|
-
def
|
76
|
-
server =
|
102
|
+
def cron_job_servers_status
|
103
|
+
server = cron_job_server
|
77
104
|
raise 'No primary server' if server.blank?
|
78
105
|
|
79
106
|
server_info = "#{server.host_name}(#{server.pid}), last check in #{server.last_check_in_at}"
|
80
107
|
raise "Primary Server is DEAD: #{server_info}" if server.dead?
|
81
108
|
|
82
|
-
report_success "Primary Server is alive: #{server_info}"
|
109
|
+
report_success "Primary Server is alive: #{server_info}",
|
110
|
+
primary_count: 1,
|
111
|
+
total_count: Cron::Server.count
|
83
112
|
rescue StandardError => error
|
84
|
-
report_error(error)
|
113
|
+
report_error(error, primary_count: 0, total_count: Cron::Server.count)
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# Desired and current worker status for servers
|
118
|
+
#
|
119
|
+
def workers_status
|
120
|
+
server = cron_job_server
|
121
|
+
raise 'No primary server' if server.blank? || server.dead?
|
122
|
+
|
123
|
+
report_success "Workers #{server.desired_server_count}/ #{server.current_server_count}",
|
124
|
+
desired_count: server.desired_server_count,
|
125
|
+
current_count: server.current_server_count
|
126
|
+
rescue StandardError => error
|
127
|
+
report_error(error, desired_count: 0, current_count: 0)
|
128
|
+
end
|
129
|
+
|
130
|
+
def cron_job_server
|
131
|
+
@cron_job_server ||= Cron::Server.primary_server
|
85
132
|
end
|
86
133
|
end
|
data/app/helpers/core_helper.rb
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
%meta{ name: 'apple-mobile-web-app-status-bar-style', content: 'black'}
|
8
8
|
= stylesheet_link_tag 'https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css'
|
9
9
|
= stylesheet_link_tag 'https://fonts.googleapis.com/icon?family=Material+Icons'
|
10
|
-
%title
|
10
|
+
%title="#{Rails.env} Status"
|
11
11
|
%body{ style: 'background-color: #006064;'}
|
12
12
|
%header
|
13
13
|
%main
|
data/lib/web47core/version.rb
CHANGED