rain_catcher 0.1.1 → 0.1.2

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: f5a8179b67bd0e585a9628916d516553f49c3b1c0023c469cdad1039a039f3e7
4
- data.tar.gz: c1dfc52ef6467aead13a9028f51d076c94e0afbb212262d59e6a9c4b1c830ccb
3
+ metadata.gz: e69ef6215e313b33dacd8494eaf81230c721aa5e5f3870041bf196e9b2d22522
4
+ data.tar.gz: 947ba71bd43c15ae2b9788b334588a278869291e06509e8297e05c4584686af5
5
5
  SHA512:
6
- metadata.gz: 792732e90285d60a51980e97d1fd0e01b64248114020d721c93ca5b92bc4d555063ef6fb4621b83d65c78fc37a7ccac96e5796266f43e63a8f76231177aead42
7
- data.tar.gz: c029628b26fabe140bb3ca97d06dc655e77f1734e117a14503cf66383995eee9ac1e24a8a92b46a4b00045f18f8eefb14796982e6f5d2b72626d80a1812d5afe
6
+ metadata.gz: '0781633bbfc99b03708a95899c13dc4b1e1fd349c6a7d2528e72dc2f40719aad107d73464a6b04f520e5001ef0d2dc7d6f9dbc2faf0d40e9e3873d58cd042f80'
7
+ data.tar.gz: ef5509c7b0c29e572726e2dc8375af8a088e0c7ed794e07a83875abe51d88bb030caa1c2635ae86aacc581c094ec387b49dc1a32b1c997c781ec62a9dec9ef87
data/.gitignore CHANGED
@@ -13,3 +13,6 @@
13
13
  # vim artefacts
14
14
  *.swo
15
15
  *.swp
16
+
17
+ *.gem
18
+ .byebug_history
data/.rubocop.yml ADDED
@@ -0,0 +1,10 @@
1
+ Style/Documentation:
2
+ Enabled: false
3
+
4
+ Metrics/BlockLength:
5
+ Exclude:
6
+ - 'spec/**/*'
7
+
8
+ AllCops:
9
+ Exclude:
10
+ - 'bin/**/*'
data/Gemfile.lock CHANGED
@@ -1,22 +1,115 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rain_catcher (0.1.0)
4
+ rain_catcher (0.1.2)
5
+ rails (~> 5.0)
6
+ raindrops (~> 0.19.0)
5
7
 
6
8
  GEM
7
9
  remote: https://rubygems.org/
8
10
  specs:
11
+ actioncable (5.2.3)
12
+ actionpack (= 5.2.3)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (>= 0.6.1)
15
+ actionmailer (5.2.3)
16
+ actionpack (= 5.2.3)
17
+ actionview (= 5.2.3)
18
+ activejob (= 5.2.3)
19
+ mail (~> 2.5, >= 2.5.4)
20
+ rails-dom-testing (~> 2.0)
21
+ actionpack (5.2.3)
22
+ actionview (= 5.2.3)
23
+ activesupport (= 5.2.3)
24
+ rack (~> 2.0)
25
+ rack-test (>= 0.6.3)
26
+ rails-dom-testing (~> 2.0)
27
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
28
+ actionview (5.2.3)
29
+ activesupport (= 5.2.3)
30
+ builder (~> 3.1)
31
+ erubi (~> 1.4)
32
+ rails-dom-testing (~> 2.0)
33
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
34
+ activejob (5.2.3)
35
+ activesupport (= 5.2.3)
36
+ globalid (>= 0.3.6)
37
+ activemodel (5.2.3)
38
+ activesupport (= 5.2.3)
39
+ activerecord (5.2.3)
40
+ activemodel (= 5.2.3)
41
+ activesupport (= 5.2.3)
42
+ arel (>= 9.0)
43
+ activestorage (5.2.3)
44
+ actionpack (= 5.2.3)
45
+ activerecord (= 5.2.3)
46
+ marcel (~> 0.3.1)
47
+ activesupport (5.2.3)
48
+ concurrent-ruby (~> 1.0, >= 1.0.2)
49
+ i18n (>= 0.7, < 2)
50
+ minitest (~> 5.1)
51
+ tzinfo (~> 1.1)
52
+ arel (9.0.0)
9
53
  ast (2.4.0)
54
+ builder (3.2.3)
55
+ byebug (11.0.1)
10
56
  concurrent-ruby (1.1.5)
57
+ crass (1.0.4)
11
58
  diff-lcs (1.3)
59
+ erubi (1.8.0)
60
+ globalid (0.4.2)
61
+ activesupport (>= 4.2.0)
12
62
  i18n (1.6.0)
13
63
  concurrent-ruby (~> 1.0)
14
64
  jaro_winkler (1.5.2)
65
+ loofah (2.2.3)
66
+ crass (~> 1.0.2)
67
+ nokogiri (>= 1.5.9)
68
+ mail (2.7.1)
69
+ mini_mime (>= 0.1.1)
70
+ marcel (0.3.3)
71
+ mimemagic (~> 0.3.2)
72
+ method_source (0.9.2)
73
+ mimemagic (0.3.3)
74
+ mini_mime (1.0.1)
75
+ mini_portile2 (2.4.0)
76
+ minitest (5.11.3)
77
+ nio4r (2.3.1)
78
+ nokogiri (1.10.3)
79
+ mini_portile2 (~> 2.4.0)
15
80
  paint (2.1.0)
16
81
  parallel (1.17.0)
17
82
  parser (2.6.3.0)
18
83
  ast (~> 2.4.0)
84
+ rack (2.0.7)
85
+ rack-test (1.1.0)
86
+ rack (>= 1.0, < 3)
87
+ rails (5.2.3)
88
+ actioncable (= 5.2.3)
89
+ actionmailer (= 5.2.3)
90
+ actionpack (= 5.2.3)
91
+ actionview (= 5.2.3)
92
+ activejob (= 5.2.3)
93
+ activemodel (= 5.2.3)
94
+ activerecord (= 5.2.3)
95
+ activestorage (= 5.2.3)
96
+ activesupport (= 5.2.3)
97
+ bundler (>= 1.3.0)
98
+ railties (= 5.2.3)
99
+ sprockets-rails (>= 2.0.0)
100
+ rails-dom-testing (2.0.3)
101
+ activesupport (>= 4.2.0)
102
+ nokogiri (>= 1.6)
103
+ rails-html-sanitizer (1.0.4)
104
+ loofah (~> 2.2, >= 2.2.2)
105
+ railties (5.2.3)
106
+ actionpack (= 5.2.3)
107
+ activesupport (= 5.2.3)
108
+ method_source
109
+ rake (>= 0.8.7)
110
+ thor (>= 0.19.0, < 2.0)
19
111
  rainbow (3.0.0)
112
+ raindrops (0.19.0)
20
113
  rake (10.5.0)
21
114
  rspec (3.8.0)
22
115
  rspec-core (~> 3.8.0)
@@ -27,6 +120,9 @@ GEM
27
120
  rspec-expectations (3.8.3)
28
121
  diff-lcs (>= 1.2.0, < 2.0)
29
122
  rspec-support (~> 3.8.0)
123
+ rspec-its (1.3.0)
124
+ rspec-core (>= 3.0.0)
125
+ rspec-expectations (>= 3.0.0)
30
126
  rspec-mocks (3.8.0)
31
127
  diff-lcs (>= 1.2.0, < 2.0)
32
128
  rspec-support (~> 3.8.0)
@@ -39,19 +135,35 @@ GEM
39
135
  ruby-progressbar (~> 1.7)
40
136
  unicode-display_width (>= 1.4.0, < 1.7)
41
137
  ruby-progressbar (1.10.0)
138
+ sprockets (3.7.2)
139
+ concurrent-ruby (~> 1.0)
140
+ rack (> 1, < 3)
141
+ sprockets-rails (3.2.1)
142
+ actionpack (>= 4.0)
143
+ activesupport (>= 4.0)
144
+ sprockets (>= 3.0.0)
42
145
  strong_versions (0.3.2)
43
146
  i18n (>= 0.5.0)
44
147
  paint (~> 2.0)
148
+ thor (0.20.3)
149
+ thread_safe (0.3.6)
150
+ tzinfo (1.2.5)
151
+ thread_safe (~> 0.1)
45
152
  unicode-display_width (1.6.0)
153
+ websocket-driver (0.7.0)
154
+ websocket-extensions (>= 0.1.0)
155
+ websocket-extensions (0.1.3)
46
156
 
47
157
  PLATFORMS
48
158
  ruby
49
159
 
50
160
  DEPENDENCIES
51
161
  bundler (~> 2.0)
162
+ byebug (~> 11.0)
52
163
  rain_catcher!
53
164
  rake (~> 10.0)
54
165
  rspec (~> 3.0)
166
+ rspec-its (~> 1.3)
55
167
  rubocop (~> 0.69.0)
56
168
  strong_versions (~> 0.3.2)
57
169
 
data/Makefile ADDED
@@ -0,0 +1,7 @@
1
+ all: test
2
+
3
+ .PHONY: test
4
+ test:
5
+ bundle exec rspec
6
+ bundle exec rubocop
7
+ bundle exec strong_versions
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # RainCatcher
2
2
 
3
- _RainCatcher_ utilises the [raindrops](https://bogomips.org/raindrops/) statistics tool to automatically log _Rack_ web server queue data for _Rails_ applications.
3
+ _RainCatcher_ utilises the [raindrops](https://bogomips.org/raindrops/) statistics tool to automatically log queue data for _Rack_ web servers (e.g. [Unicorn](https://bogomips.org/unicorn/) for _Rails_.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'rain_catcher', '~> 0.1.0'
10
+ gem 'rain_catcher', '~> 0.1.2'
11
11
  ```
12
12
 
13
13
  And rebuild your bundle:
data/lib/rain_catcher.rb CHANGED
@@ -1,7 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rails'
4
+ require 'raindrops'
5
+
3
6
  require 'rain_catcher/version'
4
7
  require 'rain_catcher/railtie'
8
+ require 'rain_catcher/subscriber'
5
9
 
6
10
  module RainCatcher
7
11
  class Error < StandardError; end
@@ -4,51 +4,40 @@ module RainCatcher
4
4
  class Railtie < Rails::Railtie
5
5
  initializer :rain_catcher do
6
6
  notifications.subscribe('process_action.action_controller') do |_args|
7
- log_if_interval_elapsed
7
+ subscriber.log_if_interval_elapsed
8
8
  end
9
9
  end
10
10
 
11
- private
11
+ class << self
12
+ private
12
13
 
13
- def notifications
14
- ActiveSupport::Notifications
15
- end
16
-
17
- def log_if_interval_elapsed
18
- return unless elapsed?
19
-
20
- Rails.logger.send(level, queue_data.to_json)
21
- @last_logged = Time.now.utc
22
- end
23
-
24
- def queue_data
25
- Raindrops::ListenStats.new(0, 0).to_h.merge(
26
- source: 'rain_catcher',
27
- application: application_name,
28
- environment: Rails.env.to_s
29
- )
30
- end
31
-
32
- def elapsed?
33
- return true if @last_logged.nil?
34
- return true if (Time.now.utc - @last_logged).seconds >= interval
14
+ def subscriber
15
+ @subscriber ||= RainCatcher::Subscriber.new(
16
+ interval: interval,
17
+ log_level: log_level,
18
+ application_name: application_name,
19
+ environment: Rails.env.to_s
20
+ )
21
+ end
35
22
 
36
- false
37
- end
23
+ def notifications
24
+ ActiveSupport::Notifications
25
+ end
38
26
 
39
- def interval
40
- @interval ||= ENV.fetch('RAIN_CATCHER_LOG_INTERVAL', '30').to_i
41
- end
27
+ def interval
28
+ ENV.fetch('RAIN_CATCHER_LOG_INTERVAL', '30').to_i
29
+ end
42
30
 
43
- def level
44
- @level ||= ENV.fetch('RAIN_CATCHER_LOG_LEVEL', 'INFO').downcase.to_sym
45
- end
31
+ def log_level
32
+ ENV.fetch('RAIN_CATCHER_LOG_LEVEL', 'INFO')
33
+ end
46
34
 
47
- def application_name
48
- @application_name ||= ENV.fetch(
49
- 'RAIN_CATCHER_APPLICATION_NAME',
50
- Rails.application.class.name.split('::').first.downcase
51
- )
35
+ def application_name
36
+ ENV.fetch(
37
+ 'RAIN_CATCHER_APPLICATION_NAME',
38
+ Rails.application.class.name.split('::').first.downcase
39
+ )
40
+ end
52
41
  end
53
42
  end
54
43
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RainCatcher
4
+ class Subscriber
5
+ def initialize(options)
6
+ @interval = options.fetch(:interval)
7
+ @log_level = options.fetch(:log_level).to_s.downcase.to_sym
8
+ @application_name = options.fetch(:application_name)
9
+ @environment = options.fetch(:environment)
10
+ @last_logged = nil
11
+ end
12
+
13
+ def log_if_interval_elapsed
14
+ return unless elapsed?
15
+
16
+ Rails.logger.send(@log_level, queue_data.to_json)
17
+ @last_logged = Time.now.utc
18
+ end
19
+
20
+ private
21
+
22
+ def queue_data
23
+ Raindrops::ListenStats.new(0, 0).to_h.merge(
24
+ source: 'rain_catcher',
25
+ application: @application_name,
26
+ environment: @environment
27
+ )
28
+ end
29
+
30
+ def elapsed?
31
+ return true if @last_logged.nil?
32
+ return true if (Time.now.utc - @last_logged).seconds >= @interval
33
+
34
+ false
35
+ end
36
+ end
37
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RainCatcher
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
data/rain_catcher.gemspec CHANGED
@@ -23,9 +23,14 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ['lib']
25
25
 
26
+ spec.add_runtime_dependency 'rails', '~> 5.0'
27
+ spec.add_runtime_dependency 'raindrops', '~> 0.19.0'
28
+
26
29
  spec.add_development_dependency 'bundler', '~> 2.0'
30
+ spec.add_development_dependency 'byebug', '~> 11.0'
27
31
  spec.add_development_dependency 'rake', '~> 10.0'
28
32
  spec.add_development_dependency 'rspec', '~> 3.0'
33
+ spec.add_development_dependency 'rspec-its', '~> 1.3'
29
34
  spec.add_development_dependency 'rubocop', '~> 0.69.0'
30
35
  spec.add_development_dependency 'strong_versions', '~> 0.3.2'
31
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rain_catcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Farrell
@@ -10,6 +10,34 @@ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2019-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: raindrops
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.19.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.19.0
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +52,20 @@ dependencies:
24
52
  - - "~>"
25
53
  - !ruby/object:Gem::Version
26
54
  version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '11.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '11.0'
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: rake
29
71
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +94,20 @@ dependencies:
52
94
  - - "~>"
53
95
  - !ruby/object:Gem::Version
54
96
  version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-its
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.3'
55
111
  - !ruby/object:Gem::Dependency
56
112
  name: rubocop
57
113
  requirement: !ruby/object:Gem::Requirement
@@ -89,16 +145,18 @@ extra_rdoc_files: []
89
145
  files:
90
146
  - ".gitignore"
91
147
  - ".rspec"
148
+ - ".rubocop.yml"
92
149
  - Gemfile
93
150
  - Gemfile.lock
151
+ - Makefile
94
152
  - README.md
95
153
  - Rakefile
96
154
  - bin/console
97
155
  - bin/setup
98
156
  - lib/rain_catcher.rb
99
157
  - lib/rain_catcher/railtie.rb
158
+ - lib/rain_catcher/subscriber.rb
100
159
  - lib/rain_catcher/version.rb
101
- - rain_catcher-0.1.0.gem
102
160
  - rain_catcher.gemspec
103
161
  homepage: https://github.com/bobf/rain_catcher
104
162
  licenses: []
Binary file