web47core 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- 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/app/models/concerns/search_able.rb +14 -0
- data/lib/app/models/email_notification.rb +3 -2
- data/lib/web47core/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 030670e1f995d60e8bf25b1fb67c9bd91a628e859225114fcfe6203f3c77e818
|
4
|
+
data.tar.gz: 7db5d7cbaa718e3a296b209bf4c5e3b943441958c0019601ec031972803f6a09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9dedd01621102e871fd5f6f19b99f46ff331788d1feba24095daf10f023c058ed61a1b7cd654e8d965c478954e41e3e53ee2c39e33efc3f46f3f4d36233e038
|
7
|
+
data.tar.gz: 1e77420c64920f5ffde02efa94def8a5d57d3832ebbff25177b80d9253949fbd26049b6e95fc952e7b5da415d9ab33d835e8e29f8032492dc888696134c806fc
|
@@ -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
|
@@ -39,6 +39,16 @@ module SearchAble
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
+
#
|
43
|
+
# Place holder to call to allow for work to be done before we gather up search text fields
|
44
|
+
#
|
45
|
+
def before_search_text; end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Place holder to call to allow for work to be done after we gather up search text fields
|
49
|
+
#
|
50
|
+
def after_search_text; end
|
51
|
+
|
42
52
|
#
|
43
53
|
# Internal: Update the search and sort text
|
44
54
|
#
|
@@ -47,8 +57,10 @@ module SearchAble
|
|
47
57
|
def update_search_and_sort_text
|
48
58
|
return if destroyed?
|
49
59
|
|
60
|
+
before_search_text
|
50
61
|
update_text(search_fields, :search_text)
|
51
62
|
update_text(sort_fields, :sort_text)
|
63
|
+
after_search_text
|
52
64
|
end
|
53
65
|
|
54
66
|
#
|
@@ -69,6 +81,8 @@ module SearchAble
|
|
69
81
|
value.to_s.rjust(4, '0')
|
70
82
|
when Array
|
71
83
|
value.empty? ? nil : value.join(' ').downcase
|
84
|
+
when Hash
|
85
|
+
value.inspect
|
72
86
|
else
|
73
87
|
value.to_s
|
74
88
|
end
|
@@ -110,6 +110,7 @@ class EmailNotification < Notification
|
|
110
110
|
mail.delivery_method :smtp, smtp_configuration
|
111
111
|
end
|
112
112
|
|
113
|
+
mail.header['X-Mailgun-Native-Send'] = 'yes' if SystemConfiguration.mail_gun_configured?
|
113
114
|
# Deliver it
|
114
115
|
mail.deliver
|
115
116
|
rescue StandardError => error
|
@@ -138,8 +139,8 @@ class EmailNotification < Notification
|
|
138
139
|
# sender address
|
139
140
|
#
|
140
141
|
def sender_address
|
141
|
-
address = SystemConfiguration.
|
142
|
-
|
142
|
+
address = SystemConfiguration.support_email
|
143
|
+
if account.present?
|
143
144
|
account_smtp = account.fetch_smtp_configuration
|
144
145
|
address = account_smtp.username if account_smtp.use?
|
145
146
|
end
|
data/lib/web47core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web47core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Schroeder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|