heartcheck 1.0.7 → 1.0.8

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
  SHA1:
3
- metadata.gz: 04f05ec6c9ea258b7b33ca3895188ca98fbd39e6
4
- data.tar.gz: b7f74dd0633149bdeef8525d273ce08cbc8a75f3
3
+ metadata.gz: e83a3e38fcfc1a22cbd39bb2925a128f36d45639
4
+ data.tar.gz: a187c15bb2b34af279b0234ad41eadb002ca3b5e
5
5
  SHA512:
6
- metadata.gz: 28ad3fe996479e114578aef5f5af8edac56b46a79c8f0ba06116e349c306f520d0347422b433a1ab036c3bafd24b957b3fc32c4e555246ef856184485b3a85ce
7
- data.tar.gz: d390551bd81ccbd549bcefc19887b12fd7bc8e1fa1e0ec84df7f569d03a00682827ab1874333c08fab1abd950d36e8014a619a154295dce563e2d9504a1131ee
6
+ metadata.gz: d8fbb3bfae6934b1dd19d5fd1844c3f87cc6db3c77b548f8f8f76cc380f8d391e18050b1f361e4340bb2c238d4f2c5f85e03fcebe363b82aa00340918be8b5c7
7
+ data.tar.gz: 986e65d78839ceda3876baccb4627c50b37fa4c9c5b3950f9c84e555929c8b934d133fd8c58ec994fce70a547f6fd919612642f6eefd09c590a93d495f8244f2
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- heartcheck (1.0.7)
4
+ heartcheck (1.0.8)
5
5
  oj
6
6
  rack (~> 1, >= 1.4.0)
7
7
 
@@ -12,6 +12,7 @@ GEM
12
12
  astrolabe (1.3.1)
13
13
  parser (~> 2.2)
14
14
  coderay (1.1.0)
15
+ concurrent-ruby (0.9.1)
15
16
  diff-lcs (1.2.5)
16
17
  method_source (0.8.2)
17
18
  oj (2.12.10)
@@ -55,6 +56,7 @@ PLATFORMS
55
56
  ruby
56
57
 
57
58
  DEPENDENCIES
59
+ concurrent-ruby (~> 0.9.1, >= 0.9.1)
58
60
  heartcheck!
59
61
  pry-nav (~> 0.2.0, >= 0.2.4)
60
62
  rack-test (~> 0.6.0, >= 0.6.3)
@@ -27,4 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency 'rack-test', '~> 0.6.0', '>= 0.6.3'
28
28
  # for documentation
29
29
  spec.add_development_dependency 'yard', '~> 0.8.0', '>= 0.8.7.6'
30
+ spec.add_development_dependency 'concurrent-ruby', '~> 0.9.1', '>= 0.9.1'
30
31
  end
@@ -13,6 +13,9 @@ module Heartcheck
13
13
  # @attr [Array<Checks>] the checks to use when checking
14
14
  attr_accessor :checks
15
15
 
16
+ # @attr [Heartcheck::Executors::Base] the checks executor backend
17
+ attr_accessor :executor
18
+
16
19
  # @attr_writer [Object] change the default logger
17
20
  attr_writer :logger
18
21
 
@@ -92,6 +95,25 @@ module Heartcheck
92
95
  checks.select { |ctx| ctx.respond_to?(:info) }
93
96
  end
94
97
 
98
+ # an executor class that respond to dispatch(checkers)
99
+ #
100
+ # @return [Heartcheck::Executors::Base]
101
+ def executor
102
+ @executor ||= Heartcheck::Executors::Base.new
103
+ end
104
+
105
+
106
+ # change current executor to a threaded implementation
107
+ # requires 'concurrent-ruby'
108
+ #
109
+ # @return [Hearcheck::Executors::Threaded]
110
+ def use_threaded_executor!
111
+ require "concurrent"
112
+ require "heartcheck/executors/threaded"
113
+
114
+ self.executor = Heartcheck::Executors::Threaded.new
115
+ end
116
+
95
117
  private
96
118
 
97
119
  # if no logger is setted we create an instance
@@ -19,7 +19,7 @@ module Heartcheck
19
19
  private
20
20
 
21
21
  def executor
22
- Heartcheck::Executors::Base.new
22
+ Heartcheck.executor
23
23
  end
24
24
  end
25
25
  end
@@ -3,11 +3,15 @@ module Heartcheck
3
3
  class Base
4
4
  def dispatch(checkers)
5
5
  checkers.map do |checker|
6
- started = Time.now
7
- checker.check.tap do |checked|
8
- checked[:time] = ((Time.now - started) * 1_000.0)
9
- Logger.info Oj.dump(checked)
10
- end
6
+ track_and_check(checker)
7
+ end
8
+ end
9
+
10
+ def track_and_check(checker)
11
+ started = Time.now
12
+ checker.check.tap do |checked|
13
+ checked[:time] = ((Time.now - started) * 1_000.0)
14
+ Logger.info Oj.dump(checked)
11
15
  end
12
16
  end
13
17
  end
@@ -0,0 +1,11 @@
1
+ module Heartcheck
2
+ module Executors
3
+ class Threaded < Heartcheck::Executors::Base
4
+ def dispatch(checkers)
5
+ checkers.collect do |checker|
6
+ Concurrent::Future.execute { track_and_check(checker) }
7
+ end.collect { |future| future.value }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -3,6 +3,13 @@ Heartcheck.setup do |monitor|
3
3
  # default value: Logger.new(STDOUT)
4
4
  # monitor.logger = Rails.logger
5
5
 
6
+ # Using threaded executor
7
+ #
8
+ # With this feature is possible to parallelize io-bound checkers
9
+ # using ruby threads, but to enable this feature you need explicitly
10
+ # install 'concurrent-ruby' gem on your project
11
+ # monitor.use_threaded_executor!
12
+
6
13
  # Checks
7
14
  # For each check you can set the folling options
8
15
  # name: String => root name to show in report page (default: class.name)
@@ -1,3 +1,3 @@
1
1
  module Heartcheck
2
- VERSION = '1.0.7'
2
+ VERSION = '1.0.8'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heartcheck
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Locaweb
@@ -164,6 +164,26 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: 0.8.7.6
167
+ - !ruby/object:Gem::Dependency
168
+ name: concurrent-ruby
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 0.9.1
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: 0.9.1
177
+ type: :development
178
+ prerelease: false
179
+ version_requirements: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - "~>"
182
+ - !ruby/object:Gem::Version
183
+ version: 0.9.1
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: 0.9.1
167
187
  description: A simple way to check your app heart.
168
188
  email:
169
189
  - desenvolvedores@locaweb.com.br
@@ -204,6 +224,7 @@ files:
204
224
  - lib/heartcheck/errors/warning.rb
205
225
  - lib/heartcheck/executors.rb
206
226
  - lib/heartcheck/executors/base.rb
227
+ - lib/heartcheck/executors/threaded.rb
207
228
  - lib/heartcheck/generators.rb
208
229
  - lib/heartcheck/generators/generator.rb
209
230
  - lib/heartcheck/generators/templates/config.rb