web47core 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61674757119e842815bc5e04cefa539820a18f5eeb140aadb0c941b656a92d30
4
- data.tar.gz: ab5f5bd12857ac2f72c62ea5543fd87ddc18e83032aa7660c34b832dff53aa14
3
+ metadata.gz: 8dcbae4501d31c989d6dbaebd98d27746bc8ade332a79a2d9f19453130fed2eb
4
+ data.tar.gz: f5f9e2daa88c92fe74467ed4f3121e7841a53c4f80f35e0c6bcc645c49456585
5
5
  SHA512:
6
- metadata.gz: bcf39a7eb437e0163a59560768047df92d0a8ebbf0226d6ec7d23a94012b2fdb38cf5e726f0776788820d4d9eccb1be062fe3fe29f221d5ada692410ed548472
7
- data.tar.gz: 0e109a6ebeee44bec442ccd3bdb1a08a2233eda70a67b51126f3a2ead61aca64b1a2f98949edbd4123e61df993b499194413af369c88b08b8e662db46c55886d
6
+ metadata.gz: a66ebb112c02a247f81b6aaadb363f5b9444995ea2ac7af47792f49f5a6f0afeed8ebceb88b19f44d47471d8705c1978dd0da06e5ef818315be7c9a342734a1e
7
+ data.tar.gz: 3cc23f38c26a06cba34e9eb719e750d010e90feb8add4c03e2cb8df33008813ea6a05ae2d46e6e2534089bae12da4d4b3fd5eb2c0288aa5eae148d9cbd77bd27
data/Gemfile.lock CHANGED
@@ -10,6 +10,7 @@ PATH
10
10
  haml
11
11
  jwt
12
12
  liquid
13
+ materialize-sass
13
14
  mongoid (> 6, < 7)
14
15
  rails (>= 4.2, < 5.3)
15
16
  redis (~> 4.1)
@@ -66,6 +67,8 @@ GEM
66
67
  public_suffix (>= 2.0.2, < 5.0)
67
68
  ansi (1.5.0)
68
69
  arel (9.0.0)
70
+ autoprefixer-rails (9.7.5)
71
+ execjs
69
72
  aws-eventstream (1.0.3)
70
73
  aws-partitions (1.290.0)
71
74
  aws-sdk-autoscaling (1.33.0)
@@ -109,6 +112,7 @@ GEM
109
112
  email_regex
110
113
  email_regex (0.0.1)
111
114
  erubi (1.9.0)
115
+ execjs (2.7.0)
112
116
  factory_bot (5.1.1)
113
117
  activesupport (>= 4.2.0)
114
118
  factory_bot_rails (5.1.1)
@@ -140,6 +144,8 @@ GEM
140
144
  mini_mime (>= 0.1.1)
141
145
  marcel (0.3.3)
142
146
  mimemagic (~> 0.3.2)
147
+ materialize-sass (1.0.0)
148
+ autoprefixer-rails (>= 6.0.3)
143
149
  method_source (1.0.0)
144
150
  mime-types (3.3.1)
145
151
  mime-types-data (~> 3.2015)
data/bin/cron_server CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
4
- require 'cron/command'
3
+ require Rails.root.join('config', 'environment')
5
4
  Cron::Worker.logger ||= Logger.new(File.join(Rails.root, 'log', 'cron_server.log'))
6
5
  Cron::Command.new(ARGV).daemonize
@@ -0,0 +1,7 @@
1
+ // Import variables here
2
+ @import 'colors'
3
+ @import 'typography'
4
+
5
+ @import 'materialize'
6
+ @import compass/utilities
7
+ @import compass/css3
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Return the status of the server
5
+ #
6
+ class StatusController < ActionController::Base
7
+ #
8
+ # Main (and only) page
9
+ #
10
+ def index
11
+ components = { mongo: mongo_status, redis: redis_status, job_count: job_count_status, cron_job: cron_job_status }
12
+
13
+ respond_to do |format|
14
+ format.html { render :index, locals: { components: components }, layout: false }
15
+ 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
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ #
26
+ # Report an error for the check
27
+ #
28
+ def report_error(error)
29
+ { success: false, icon_name: 'error', icon_color: 'red-text', message: error.message }
30
+ end
31
+
32
+ #
33
+ # Report a success for the check
34
+ #
35
+ def report_success(message)
36
+ { success: true, icon_name: 'check_circle', icon_color: 'green-text', message: message }
37
+ end
38
+
39
+ #
40
+ # Mongo DB status
41
+ #
42
+ def mongo_status
43
+ raise 'Mongo not available' if SystemConfiguration.count.zero?
44
+
45
+ report_success "#{SystemConfiguration.count} Configs"
46
+ rescue StandardError => error
47
+ report_error(error)
48
+ end
49
+
50
+ #
51
+ # Redis DB Status
52
+ #
53
+ def redis_status
54
+ value = Time.now.to_f
55
+ Rails.cache.write 'redis-status-check', value
56
+ raise 'Redis not available' unless value.eql?(Rails.cache.fetch('redis-status-check'))
57
+
58
+ report_success 'Redis Available'
59
+ rescue StandardError => error
60
+ report_error(error)
61
+ end
62
+
63
+ #
64
+ # Job Count
65
+ #
66
+ def job_count_status
67
+ report_success "#{Delayed::Backend::Mongoid::Job.count} Jobs"
68
+ rescue StandardError => error
69
+ report_error(error)
70
+ end
71
+
72
+ #
73
+ # Cron job status
74
+ #
75
+ def cron_job_status
76
+ server = Cron::Server.primary_server
77
+ raise 'No primary server' if server.blank?
78
+
79
+ server_info = "#{server.host_name}(#{server.pid}), last check in #{server.last_check_in_at}"
80
+ raise "Primary Server is DEAD: #{server_info}" if server.dead?
81
+
82
+ report_success "Primary Server is alive: #{server_info}"
83
+ rescue StandardError => error
84
+ report_error(error)
85
+ end
86
+ end
@@ -0,0 +1,38 @@
1
+ !!!
2
+ %html{ lang: 'en-US' }
3
+ %head
4
+ %meta{charset: 'utf-8'}
5
+ %meta{ name: 'viewport', content: 'initial-scale=1.0, width=device-width' }
6
+ %meta{ name: 'apple-mobile-web-app-capable', content: 'yes'}
7
+ %meta{ name: 'apple-mobile-web-app-status-bar-style', content: 'black'}
8
+ = stylesheet_link_tag 'application'
9
+ = stylesheet_link_tag 'https://fonts.googleapis.com/icon?family=Material+Icons'
10
+ %title "#{Rails.env} Status"
11
+ %body{ style: 'background-color: #006064;'}
12
+ %header
13
+ %main
14
+ .container{ style: 'background-color: #cfd8dc;'}
15
+ .row
16
+ .col.s12
17
+ %h2.flow-text.center.grey-text=Rails.env.titleize
18
+ .row
19
+ .col.s12
20
+ %table.striped
21
+ %thead
22
+ %tr
23
+ %th
24
+ %h3.flow-text Component
25
+ %th.center
26
+ %h3.flow-text Status
27
+ %th.center.hide-on-small-only
28
+ %h3.flow-text Message
29
+ %tbody
30
+ - components.each do |key, value|
31
+ %tr
32
+ %td
33
+ %h4.flow-text=key.to_s.titleize
34
+ %td.center
35
+ %i.material-icons.medium{class: value[:icon_color]}
36
+ = value[:icon_name]
37
+ %td.center.hide-on-small-only
38
+ %h4.flow-text.large=value[:message]
@@ -0,0 +1,158 @@
1
+ # require 'test_helper'
2
+ # class StatusControllerTest < ActionDispatch::IntegrationTest
3
+ #
4
+ # context 'mongo status' do
5
+ # should 'pass mongo' do
6
+ # SystemConfiguration.configuration
7
+ # get status_index_path
8
+ # assert_response :success
9
+ # assert_select 'table', 1 do |table|
10
+ # assert_select table, 'tbody', 1 do |body|
11
+ # assert_select body, 'tr[1]', 1 do |row|
12
+ # assert_select row, 'td[2]', 1 do |col|
13
+ # assert_select col, 'i', 'check_circle', col
14
+ # end
15
+ # end
16
+ # end
17
+ # end
18
+ # end
19
+ # should 'render json' do
20
+ # SystemConfiguration.configuration
21
+ # get "/status.json"
22
+ # assert_response :success
23
+ # json = JSON.parse(response.body)
24
+ # mongo = json['mongo']
25
+ # assert mongo['success'], mongo.inspect
26
+ # assert_equal '1 Configs', mongo['message'], mongo.inspect
27
+ # end
28
+ # should 'render text success' do
29
+ # Cron::Server.find_or_create_server.become_primary
30
+ # SystemConfiguration.configuration
31
+ # get "/status.text"
32
+ # assert_response :success
33
+ # end
34
+ # should 'fail mongo' do
35
+ # SystemConfiguration.destroy_all
36
+ # get status_index_path
37
+ # assert_response :success
38
+ # assert_select 'table', 1 do |table|
39
+ # assert_select table, 'tbody', 1 do |body|
40
+ # assert_select body, 'tr[1]', 1 do |row|
41
+ # assert_select row, 'td[2]', 1 do |col|
42
+ # assert_select col, "i", 'error', col
43
+ # end
44
+ # end
45
+ # end
46
+ # end
47
+ # end
48
+ # should 'render json fail' do
49
+ # SystemConfiguration.destroy_all
50
+ # get "/status.json"
51
+ # assert_response :success
52
+ # json = JSON.parse(response.body)
53
+ # mongo = json['mongo']
54
+ # refute mongo['success'], mongo.inspect
55
+ # end
56
+ # should 'render text fail' do
57
+ # SystemConfiguration.destroy_all
58
+ # get "/status.text"
59
+ # assert_response :internal_server_error
60
+ # end
61
+ # end
62
+ #
63
+ # context 'redis status' do
64
+ # should 'pass redis' do
65
+ # get status_index_path
66
+ # assert_response :success
67
+ # # puts(response.body)
68
+ # assert_select 'table', 1 do |table|
69
+ # assert_select table, 'tbody', 1 do |body|
70
+ # assert_select body, 'tr[2]', 1 do |row|
71
+ # assert_select row, 'td[2]', 1 do |col|
72
+ # assert_select col, 'i', 'check_circle', col
73
+ # end
74
+ # end
75
+ # end
76
+ # end
77
+ # end
78
+ # should 'fail redis' do
79
+ # Rails.cache.expects(:write).once.raises('Redis not available')
80
+ # get status_index_path
81
+ # # Rails.cache.set 'redis-status-check', value
82
+ # assert_response :success
83
+ # assert_select 'table', 1 do |table|
84
+ # assert_select table, 'tbody', 1 do |body|
85
+ # assert_select body, 'tr[2]', 1 do |row|
86
+ # assert_select row, 'td[2]', 1 do |col|
87
+ # assert_select col, "i", 'error', col
88
+ # end
89
+ # end
90
+ # end
91
+ # end
92
+ # end
93
+ # end
94
+ #
95
+ # context 'job count' do
96
+ # should 'display job count' do
97
+ # get status_index_path
98
+ # assert_response :success
99
+ # assert_select 'td', "#{Delayed::Backend::Mongoid::Job.count} Jobs", response.body
100
+ # end
101
+ # end
102
+ #
103
+ # context 'cron job status' do
104
+ # should 'pass cron job' do
105
+ # server = Cron::Server.find_or_create_server
106
+ # server.become_primary
107
+ #
108
+ # get status_index_path
109
+ # assert_response :success
110
+ # assert_select 'table', 1 do |table|
111
+ # assert_select table, 'tbody', 1 do |body|
112
+ # assert_select body, 'tr[4]', 1 do |row|
113
+ # assert_select row, 'td[2]', 1 do |col|
114
+ # assert_select col, 'i', 'check_circle', col
115
+ # end
116
+ # assert_select row, 'td[3]', 1 do |col|
117
+ # assert_select col, 'h4', "Primary Server is alive: #{server.host_name}(#{server.pid}), last check in #{server.last_check_in_at}", col
118
+ # end
119
+ # end
120
+ # end
121
+ # end
122
+ # end
123
+ # should 'fail cron job with dead primary server' do
124
+ # server = Cron::Server.find_or_create_server
125
+ # server.become_primary
126
+ # server.set last_check_in_at: 1.days.ago.utc
127
+ #
128
+ # get status_index_path
129
+ # assert_response :success
130
+ # assert_select 'table', 1 do |table|
131
+ # assert_select table, 'tbody', 1 do |body|
132
+ # assert_select body, 'tr[4]', 1 do |row|
133
+ # assert_select row, 'td[2]', 1 do |col|
134
+ # assert_select col, 'i', 'error', col
135
+ # end
136
+ # assert_select row, 'td[3]', 1 do |col|
137
+ # assert_select col, 'h4', "Primary Server is DEAD: #{server.host_name}(#{server.pid}), last check in #{server.last_check_in_at}", col
138
+ # end
139
+ # end
140
+ # end
141
+ # end
142
+ # end
143
+ # should 'fail cron job' do
144
+ # Cron::Server.find_or_create_server
145
+ # get status_index_path
146
+ # assert_response :success
147
+ # assert_select 'table', 1 do |table|
148
+ # assert_select table, 'tbody', 1 do |body|
149
+ # assert_select body, 'tr[4]', 1 do |row|
150
+ # assert_select row, 'td[2]', 1 do |col|
151
+ # assert_select col, "i", 'error', col
152
+ # end
153
+ # end
154
+ # end
155
+ # end
156
+ # end
157
+ # end
158
+ # end
data/web47core.gemspec CHANGED
@@ -8,7 +8,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
8
8
  Gem::Specification.new do |spec|
9
9
  spec.required_ruby_version = '~> 2.4.1'
10
10
  spec.name = 'web47core'
11
- spec.version = '0.1.2'
11
+ spec.version = '0.1.3'
12
12
  spec.authors = ['Chris Schroeder']
13
13
  spec.email = ['chris@app47.com']
14
14
  spec.summary = 'App47 Web Core Library.'
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.add_runtime_dependency 'haml'
33
33
  spec.add_runtime_dependency 'jwt'
34
34
  spec.add_runtime_dependency 'liquid'
35
+ spec.add_runtime_dependency 'materialize-sass'
35
36
  spec.add_runtime_dependency 'mongoid', '> 6', '< 7'
36
37
  spec.add_runtime_dependency 'rails', '< 5.3', '>= 4.2'
37
38
  spec.add_runtime_dependency 'redis', '~> 4.1'
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.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Schroeder
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: materialize-sass
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: mongoid
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -506,6 +520,8 @@ files:
506
520
  - Rakefile
507
521
  - bin/cron_server
508
522
  - config/locales/en.yml
523
+ - lib/app/assets/stylesheets/status.sass
524
+ - lib/app/controllers/status_controller.rb
509
525
  - lib/app/jobs/application_job.rb
510
526
  - lib/app/jobs/cron/command.rb
511
527
  - lib/app/jobs/cron/job.rb
@@ -538,11 +554,13 @@ files:
538
554
  - lib/app/models/sms_notification.rb
539
555
  - lib/app/models/smtp_configuration.rb
540
556
  - lib/app/models/template.rb
557
+ - lib/app/views/status/index.html.haml
541
558
  - lib/templates/email/notification_failure.liquid
542
559
  - lib/templates/email/notification_failure.subject.liquid
543
560
  - lib/templates/slack/error_message.liquid
544
561
  - lib/templates/slack/failed_delayed_job.liquid
545
562
  - lib/web47core.rb
563
+ - test/controllers/status_controller_test.rb
546
564
  - test/factories/account_factories.rb
547
565
  - test/factories/notification_factories.rb
548
566
  - test/fixtures/mongoid.yml
@@ -599,6 +617,7 @@ signing_key:
599
617
  specification_version: 4
600
618
  summary: App47 Web Core Library.
601
619
  test_files:
620
+ - test/controllers/status_controller_test.rb
602
621
  - test/factories/account_factories.rb
603
622
  - test/factories/notification_factories.rb
604
623
  - test/fixtures/mongoid.yml