web47core 0.6.0 → 0.6.1

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
  SHA256:
3
- metadata.gz: d4ca49b23de02bb0334025734b0616e2a99a4c13cebd882195fffdcfb06f51ec
4
- data.tar.gz: 5f0a329a5ff30a79edf739e44d84f43846cf27e385dcd87f421f008871ed3335
3
+ metadata.gz: 0df839ec2a6e7d78c8ef4e250179643a359e0b5723b35992ab4dfda76ccd1886
4
+ data.tar.gz: 31b961889cc2bf8748da8b2ea26d050a20fed870adfdcc68a5e8bce1f0e67409
5
5
  SHA512:
6
- metadata.gz: 13750d4f9b2a249b8e1448c83f7e5dca0a42a78bba268e8de7f6467faa52d9b73feca83a991cc665305b7edd93f1883818741cf9189d4d8285ff5f4acbd6df4a
7
- data.tar.gz: 4d7e3e1378637aa08b0ac7e60b984a0faf743ebdab1af52fbc43dfcf5f6ace391882647de5b94567b713f7648ed3feff45e3e751e159e401f2e235af93b9a9b3
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, redis: redis_status, job_count: job_count_status, cron_job: cron_job_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 do
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
- { success: false, icon_name: 'error', icon_color: 'red-text', message: error.message }
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
- { success: true, icon_name: 'check_circle', icon_color: 'green-text', message: message }
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(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 job_count_status
67
- report_success "#{Delayed::Backend::Mongoid::Job.count} Jobs"
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 cron_job_status
76
- server = Cron::Server.primary_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
@@ -91,8 +91,4 @@ module CoreHelper
91
91
  def edit_model_path(model)
92
92
  model_action_path(model, :edit)
93
93
  end
94
-
95
- def current_user
96
- User.new
97
- end
98
94
  end
@@ -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 "#{Rails.env} Status"
10
+ %title="#{Rails.env} Status"
11
11
  %body{ style: 'background-color: #006064;'}
12
12
  %header
13
13
  %main
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Web47core
4
- VERSION = '0.6.0'
4
+ VERSION = '0.6.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web47core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Schroeder