process_handler 2.3.0 → 3.0.0

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: 16ff070c1f4e04220f402a1269a7f2e41bd5f6ba
4
- data.tar.gz: 551acbbe76055fff1fb1f49e1359d6a4e9eb48c5
3
+ metadata.gz: 3e495c8a8ec6bf3798941bd11f2792b9a28f1c95
4
+ data.tar.gz: 8923ae242c65ba6120b48184588b2534060ff831
5
5
  SHA512:
6
- metadata.gz: 1da185b0c6a35a84a5989aaeebdc4ac72914f439999b8bce185f117f46400239c097b50238807a453d526042193b295ff85162c5156429cb688bc7a4b1a77d60
7
- data.tar.gz: 42f98184302acd238e21ca550956fc47e78f4b7852c5bde1bad6f42679d897d4db3b769e0b619a3e41cc1134081357accdac6b4eb6a7ed99d222d31029966a25
6
+ metadata.gz: 337003df5486731c3b8addbb93e85159e664f20996fda1b22252e111d09831a1b735b3962f242f3f1ec44c88340025ca80356ebf468a1f610be5bc96b2870812
7
+ data.tar.gz: 33b8e7e9d3d0f4368a53f11610449b0e5394177cf286495a52d843885e077425d3ff486621ae9a107c8ad2e05e91ec3550b7bea80f79b4de5436c5049379bfc4
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ gem 'rufus-scheduler', '~> 3.2.1'
5
5
  gem 'logasm'
6
6
 
7
7
  group :test do
8
- gem 'rspec', '~> 3.1.0'
8
+ gem 'rspec', '~> 3.4'
9
9
  gem 'pry'
10
10
  end
11
11
 
@@ -13,9 +13,7 @@ module Salemove
13
13
  end
14
14
 
15
15
  def on_error(job, error)
16
- if @exception_notifier
17
- @exception_notifier.notify_or_ignore(error, cgi_data: ENV.to_hash)
18
- end
16
+ @exception_notifier.notify_or_ignore(error, {}) if @exception_notifier
19
17
  super
20
18
  end
21
19
 
@@ -8,19 +8,20 @@ module Salemove
8
8
 
9
9
  def self.get_notifier(process_name, conf)
10
10
  if conf && conf[:type] == 'airbrake'
11
- Airbrake.configure do |airbrake|
12
- airbrake.async = true
13
- airbrake.environment_name = conf.fetch(:environment_name)
14
- airbrake.secure = true
11
+ notifier_name = conf[:notifier_name] || :default
12
+ Airbrake.configure(notifier_name) do |airbrake|
13
+ airbrake.environment = conf.fetch(:environment)
15
14
  airbrake.host = conf.fetch(:host)
16
- airbrake.api_key = conf.fetch(:api_key)
17
- [/_HOST$/, /_TCP$/, /_UDP$/, /_PROTO$/, /_ADDR$/, 'PWD',
18
- 'GEM_HOME', 'PATH', 'SERVICE_NAME', 'RUBY_MAJOR', 'RUBY_VERSION',
19
- 'RUN_ENV', 'HOME', 'RUBYGEMS_VERSION', 'BUNDLER_VERSION'].each {
20
- | param_whitelist_filter| airbrake.params_whitelist_filters << param_whitelist_filter
21
- }
15
+ airbrake.project_id = conf.fetch(:project_id)
16
+ airbrake.project_key = conf.fetch(:project_key)
17
+ airbrake.ignore_environments = conf[:ignore_environments] if conf[:ignore_environments]
18
+ airbrake.whitelist_keys = [
19
+ /_HOST$/, /_TCP$/, /_UDP$/, /_PROTO$/, /_ADDR$/, 'PWD',
20
+ 'GEM_HOME', 'PATH', 'SERVICE_NAME', 'RUBY_MAJOR', 'RUBY_VERSION',
21
+ 'RACK_ENV', 'RUN_ENV', 'HOME', 'RUBYGEMS_VERSION', 'BUNDLER_VERSION'
22
+ ]
22
23
  end
23
- Airbrake
24
+ AirbrakeNotifier.new
24
25
  elsif conf && conf[:type] == 'growl'
25
26
  GrowlNotifier.new(process_name)
26
27
  elsif conf && conf[:type] == 'terminal-notifier'
@@ -29,13 +30,19 @@ module Salemove
29
30
  end
30
31
  end
31
32
 
33
+ class AirbrakeNotifier
34
+ def notify_or_ignore(error, params)
35
+ Airbrake.notify(error, params)
36
+ end
37
+ end
38
+
32
39
  class GrowlNotifier
33
40
  def initialize(process_name)
34
41
  @process_name = process_name
35
42
  end
36
43
 
37
44
  def notify_or_ignore(error, _)
38
- Growl.notify error.message, title: "Error in #{@process_name}"
45
+ Growl.notify(error.message, title: "Error in #{@process_name}")
39
46
  end
40
47
  end
41
48
 
@@ -113,13 +113,7 @@ module Salemove
113
113
  message = [exception.inspect, *exception.backtrace].join("\n")
114
114
  @logger.error(message, input)
115
115
 
116
- if @exception_notifier
117
- @exception_notifier.notify_or_ignore(
118
- exception,
119
- cgi_data: ENV.to_hash,
120
- parameters: input
121
- )
122
- end
116
+ @exception_notifier.notify_or_ignore(exception, input) if @exception_notifier
123
117
  end
124
118
  end
125
119
 
@@ -207,13 +201,7 @@ module Salemove
207
201
  message = [exception.inspect, *exception.backtrace].join("\n")
208
202
  @logger.error(message, input)
209
203
 
210
- if @exception_notifier
211
- @exception_notifier.notify_or_ignore(
212
- exception,
213
- cgi_data: ENV.to_hash,
214
- parameters: input
215
- )
216
- end
204
+ @exception_notifier.notify_or_ignore(exception, input) if @exception_notifier
217
205
 
218
206
  { success: false, error: exception.message }
219
207
  end
@@ -1,5 +1,5 @@
1
1
  module Salemove
2
2
  module ProcessHandler
3
- VERSION = '2.3.0'
3
+ VERSION = '3.0.0'
4
4
  end
5
5
  end
@@ -18,7 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency 'airbrake', '~> 4.3'
21
+ spec.add_dependency 'airbrake', '~> 7.4'
22
+ spec.add_dependency 'timers', '~> 4.1.2'
22
23
  spec.add_dependency 'sucker_punch', '~> 1.1' # for async airbrake notifications
23
24
  spec.add_dependency 'growl'
24
25
  spec.add_dependency 'terminal-notifier'
@@ -1,63 +1,61 @@
1
1
  require 'spec_helper'
2
- require 'airbrake'
3
- require 'airbrake/notice'
4
2
  require 'salemove/process_handler/notifier_factory'
3
+ require 'securerandom'
5
4
 
6
5
  describe 'Airbrake configuration' do
7
-
8
- let (:notice) { Airbrake::Notice.new(notice_args.merge(custom_notice_args)) }
9
- let (:environment_name) { 'SOME_ENVIRONMENT' }
10
- let (:notifier_factory_conf) { {:type => 'airbrake',
11
- :host => 'localhost',
12
- :api_key => 'abc123',
13
- :environment_name => environment_name} }
14
- let (:airbrake) { ProcessHandler::NotifierFactory.get_notifier('Process name', notifier_factory_conf) }
15
- # Notice needs Airbrake configuration merged with :exception for creating the exception notification
16
- let (:notice_args) { {:exception => Exception.new}.merge(airbrake.configuration) }
17
- let (:custom_notice_args) { {} }
18
- let (:filtered) { '[FILTERED]' }
19
-
20
- # Uses Airbrake configuration's 'params_whitelist_filters' param for filtering
21
- describe 'whitelist filtering' do
22
-
23
- let (:custom_notice_args) {
24
- {
25
- :params_filters => [], # Remove blacklist to test whitelist
26
- :parameters => {
27
- 'API_PORT_80_TCP_PROTO' => 'tcp',
28
- 'HOME' => '/home/sm',
29
- 'SECRET_PASS' => 'Parool123',
30
- 'SOME_PROTO_KEY' => 'value',
31
- 'PROTO_KEY' => 'abc123'
32
- },
33
- :cgi_data => {
34
- 'HTTP_HOST' => 'localhost:3001',
35
- 'RANDOM' => 'value',
36
- 'HOME' => 'sweet home'
37
- }
38
- }
6
+ let(:environment) { 'SOME_ENVIRONMENT' }
7
+ let(:config) { airbrake_config.merge(type: 'airbrake') }
8
+ let(:airbrake_config) { base_params }
9
+ let(:base_params) do
10
+ {
11
+ environment: environment,
12
+ host: 'localhost',
13
+ project_id: '123456',
14
+ project_key: 'abc123',
15
+ ignore_environments: ['dev'],
16
+ # Airbrake module raises an error when same notifier configured multiple times
17
+ # Provide a random notifier name for each test case
18
+ notifier_name: SecureRandom.hex
39
19
  }
20
+ end
21
+ let(:airbrake) do
22
+ ProcessHandler::NotifierFactory.get_notifier('Process name', config)
23
+ end
40
24
 
41
- it 'allows parameters by regex' do
42
- expect(notice[:parameters]['API_PORT_80_TCP_PROTO']).to eq 'tcp'
43
- expect(notice[:cgi_data]['HTTP_HOST']).to eq 'localhost:3001'
25
+ context 'when all params set' do
26
+ it 'does not raise an error' do
27
+ expect { airbrake }.not_to raise_error
44
28
  end
29
+ end
45
30
 
46
- it 'allows parameters by string' do
47
- expect(notice[:parameters]['HOME']).to eq '/home/sm'
48
- expect(notice[:cgi_data]['HOME']).to eq 'sweet home'
49
- end
31
+ context 'when project_id is not a number' do
32
+ let(:airbrake_config) { base_params.merge(project_id: 'abc') }
50
33
 
51
- it 'filters variables not in whitelist' do
52
- expect(notice[:parameters]['SECRET_PASS']).to eq filtered
53
- expect(notice[:parameters]['SOME_PROTO_KEY']).to eq filtered
54
- expect(notice[:parameters]['PROTO_KEY']).to eq filtered
55
- expect(notice[:cgi_data]['RANDOM']).to eq filtered
34
+ it 'raises error' do
35
+ expect { airbrake }.to raise_error
56
36
  end
37
+ end
57
38
 
39
+ context 'when ignore_environments missing' do
40
+ before { base_params.delete(:ignore_environments) }
41
+
42
+ it 'does not raise an error' do
43
+ expect { airbrake }.not_to raise_error
44
+ end
58
45
  end
59
46
 
60
- it 'configures environment_name' do
61
- expect(notice[:environment_name]).to eq environment_name
47
+ shared_examples_for 'raises error if config param missing' do |key|
48
+ context "when #{key} missing" do
49
+ before { base_params.delete(key) }
50
+
51
+ it 'raises error' do
52
+ expect { airbrake }.to raise_error
53
+ end
54
+ end
62
55
  end
56
+
57
+ it_behaves_like 'raises error if config param missing', :environment
58
+ it_behaves_like 'raises error if config param missing', :host
59
+ it_behaves_like 'raises error if config param missing', :project_id
60
+ it_behaves_like 'raises error if config param missing', :project_key
63
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: process_handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SaleMove TechMovers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-08 00:00:00.000000000 Z
11
+ date: 2018-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: airbrake
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.3'
19
+ version: '7.4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.3'
26
+ version: '7.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: timers
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 4.1.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 4.1.2
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: sucker_punch
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -118,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
132
  version: '0'
119
133
  requirements: []
120
134
  rubyforge_project:
121
- rubygems_version: 2.6.11
135
+ rubygems_version: 2.2.5
122
136
  signing_key:
123
137
  specification_version: 4
124
138
  summary: ''