health-monitor-rails 0.0.19 → 0.1.0

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
  SHA1:
3
- metadata.gz: c7695d8ca5e37274f02ef91ed76567b927d49fa6
4
- data.tar.gz: 34b479494f5c09270a48d72a0592d1727c6facc0
3
+ metadata.gz: 30793122295e562eb958e0d584ca7c554092af4c
4
+ data.tar.gz: 90982b94a76c8bd353b0a16619d67ee1315a5329
5
5
  SHA512:
6
- metadata.gz: aa7af0c50693f41ff326b5b7ff4a3f13d7b70fa0eb3ac3a51055ff1af1c93320e0498a273566bc724f2a0381bf8bb2e616354e39d6dc022752f7a811291de220
7
- data.tar.gz: cca363173ec7cba02bf9c821c9b65c43a8452077a23077bd03cec4e916384fd044e0f22bac157bbfa8d918a190eb71d683c819f4f38941873ed3afde61b44f77
6
+ metadata.gz: b954f90b79b405c5cf37184dee94c23fe7c2849c72cdae075bac85bf53c76ba8f6dbad1d815e1c1f04ccdba5861fe88ba46a2e72309031bbe6e7c4af5ce12576
7
+ data.tar.gz: fcfe2fe1ee6dc1ef8776e69dbda09a63abc34e79a2380161ff9b5e2922a1ec67433c3a0b5e8f309694c7bc8cfad16798162ca24886fbe014bfa50190a0324547
@@ -7,7 +7,7 @@ module HealthMonitor
7
7
 
8
8
  # GET /health/check
9
9
  def check
10
- HealthMonitor.check!
10
+ HealthMonitor.check!(request: request)
11
11
 
12
12
  self.status = :ok
13
13
  self.response_body = "Health check has passed: #{Time.now.to_s(:db)}\n"
@@ -11,11 +11,11 @@ module HealthMonitor
11
11
  yield configuration if block_given?
12
12
  end
13
13
 
14
- def check!
14
+ def check!(request: nil)
15
15
  configuration.providers.each do |provider|
16
16
  require "health_monitor/providers/#{provider}"
17
17
 
18
- monitor = "HealthMonitor::Providers::#{provider.capitalize}".constantize.new
18
+ monitor = "HealthMonitor::Providers::#{provider.capitalize}".constantize.new(request: request)
19
19
  monitor.check!
20
20
  end
21
21
  rescue Exception => e
@@ -0,0 +1,16 @@
1
+ module HealthMonitor
2
+ module Providers
3
+ class Base
4
+ attr_reader :request
5
+
6
+ def initialize(request: nil)
7
+ @request = request
8
+ end
9
+
10
+ # @abstract
11
+ def check!
12
+ raise NotImplementedError
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,18 +1,26 @@
1
+ require 'health_monitor/providers/base'
2
+
1
3
  module HealthMonitor
2
4
  module Providers
3
5
  class CacheException < StandardError; end
4
6
 
5
- class Cache
7
+ class Cache < Base
6
8
  def check!
7
9
  time = Time.now.to_s
8
10
 
9
- Rails.cache.write(:health, time)
10
- fetched = Rails.cache.read(:health)
11
+ Rails.cache.write(key, time)
12
+ fetched = Rails.cache.read(key)
11
13
 
12
14
  raise "different values (now: #{time}, fetched: #{fetched}" if fetched != time
13
15
  rescue Exception => e
14
16
  raise CacheException.new(e.message)
15
17
  end
18
+
19
+ private
20
+
21
+ def key
22
+ @key ||= ['health', request.try(:remote_ip)].join('_')
23
+ end
16
24
  end
17
25
  end
18
26
  end
@@ -1,8 +1,10 @@
1
+ require 'health_monitor/providers/base'
2
+
1
3
  module HealthMonitor
2
4
  module Providers
3
5
  class DatabaseException < StandardError; end
4
6
 
5
- class Database
7
+ class Database < Base
6
8
  def check!
7
9
  # Check connection to the DB:
8
10
  ActiveRecord::Migrator.current_version
@@ -1,21 +1,28 @@
1
+ require 'health_monitor/providers/base'
1
2
  require 'redis/namespace'
2
3
 
3
4
  module HealthMonitor
4
5
  module Providers
5
6
  class RedisException < StandardError; end
6
7
 
7
- class Redis
8
+ class Redis < Base
8
9
  def check!
9
10
  time = Time.now.to_s(:db)
10
11
 
11
12
  r = ::Redis.new
12
- r.set(:health, time)
13
- fetched = r.get(:health)
13
+ r.set(key, time)
14
+ fetched = r.get(key)
14
15
 
15
16
  raise "different values (now: #{time}, fetched: #{fetched}" if fetched != time
16
17
  rescue => e
17
18
  raise RedisException.new(e.message)
18
19
  end
20
+
21
+ private
22
+
23
+ def key
24
+ @key ||= ['health', request.try(:remote_ip)].join('_')
25
+ end
19
26
  end
20
27
  end
21
28
  end
@@ -1,10 +1,11 @@
1
+ require 'health_monitor/providers/base'
1
2
  require 'resque'
2
3
 
3
4
  module HealthMonitor
4
5
  module Providers
5
6
  class ResqueException < StandardError; end
6
7
 
7
- class Resque
8
+ class Resque < Base
8
9
  def check!
9
10
  ::Resque.info
10
11
  rescue Exception => e
@@ -1,10 +1,11 @@
1
+ require 'health_monitor/providers/base'
1
2
  require 'sidekiq/api'
2
3
 
3
4
  module HealthMonitor
4
5
  module Providers
5
6
  class SidekiqException < StandardError; end
6
7
 
7
- class Sidekiq
8
+ class Sidekiq < Base
8
9
  def check!
9
10
  check_workers!
10
11
  check_redis!
@@ -1,3 +1,3 @@
1
1
  module HealthMonitor
2
- VERSION = '0.0.19'.freeze
2
+ VERSION = '0.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: health-monitor-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonid Beder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-31 00:00:00.000000000 Z
11
+ date: 2014-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -180,6 +180,7 @@ files:
180
180
  - lib/health_monitor/configuration.rb
181
181
  - lib/health_monitor/engine.rb
182
182
  - lib/health_monitor/monitor.rb
183
+ - lib/health_monitor/providers/base.rb
183
184
  - lib/health_monitor/providers/cache.rb
184
185
  - lib/health_monitor/providers/database.rb
185
186
  - lib/health_monitor/providers/redis.rb