rabbit_jobs 0.8.20 → 0.9.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: 6ae8280cb0507c08c0bd8603349ca504b389d986
4
- data.tar.gz: 277bd310798482e364287b14530a029d6888bc13
3
+ metadata.gz: 01b64dc9a1dacb4d8c9bd59e049760bf13f64933
4
+ data.tar.gz: 17681bfe86634638d2e50ff33140a44e89123977
5
5
  SHA512:
6
- metadata.gz: 6569f377bce44b954ed3de7485547294a52e246c7acda1019b23b06fa82236450106f3c0a73e5b4c425747029c3750e23a6a80f143bd23e5ae584121ce83df93
7
- data.tar.gz: f8f8872fb78f74014d7767d48d169e5637bf967573c5dc3857b708c3c214da49994c56f9c11578c6217c22c7ed1994e43f7ce2b0401cd53e76c698a188b1c626
6
+ metadata.gz: 65c444a292677f156f2a9518bd1971e9d6da5ed9aecfabf024054dca25d9fe623d31d75065cb75602d31d1d851d9cdcee354b6443da98c3d92a8da1d0385d446
7
+ data.tar.gz: 4dd5ac992c47ae2f1d39f6931fe584c658c25d6449f4f1ce7867751045a401f1e7f9e184ac2258dae6ad3a80a3a1569cbdf2dae054aa74f1a0ad923a9ae8a002
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ spec/reports
16
16
  test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
+ *._.*
data/Gemfile CHANGED
@@ -3,8 +3,6 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :development do
6
- gem 'actionmailer', '>= 3.0'
7
-
8
6
  gem 'timecop'
9
7
  gem 'rspec', '~> 2.8'
10
8
  gem 'rr'
data/lib/rabbit_jobs.rb CHANGED
@@ -15,7 +15,6 @@ require 'rabbit_jobs/version'
15
15
 
16
16
  require 'rabbit_jobs/helpers'
17
17
  require 'rabbit_jobs/configuration'
18
- require 'rabbit_jobs/error_mailer'
19
18
 
20
19
  require 'rabbit_jobs/consumer/job_consumer'
21
20
  require 'rabbit_jobs/job'
@@ -77,22 +77,6 @@ module RabbitJobs
77
77
  end
78
78
  end
79
79
 
80
- def mail_errors_to(email = nil)
81
- if email
82
- @data[:mail_errors_to] = email
83
- else
84
- @data[:mail_errors_to]
85
- end
86
- end
87
-
88
- def mail_errors_from(email = nil)
89
- if email
90
- @data[:mail_errors_from] = email
91
- else
92
- @data[:mail_errors_from]
93
- end
94
- end
95
-
96
80
  def error_log
97
81
  @data[:error_log]
98
82
  end
@@ -135,7 +119,7 @@ module RabbitJobs
135
119
  yaml = parse_environment(yaml)
136
120
 
137
121
  @data = {queues: {}}
138
- %w(server mail_errors_to mail_errors_from default_queue).each do |m|
122
+ %w(server default_queue).each do |m|
139
123
  self.send(m, yaml[m])
140
124
  end
141
125
  yaml['queues'].each do |name, params|
@@ -19,15 +19,6 @@ module RabbitJobs
19
19
  true
20
20
  end
21
21
 
22
- def log_error(msg_or_exception, payload = nil)
23
- if msg_or_exception.is_a?(String)
24
- RJ.logger.error msg_or_exception
25
- else
26
- RJ.logger.error msg_or_exception.message
27
- RJ.logger.error _cleanup_backtrace(msg_or_exception.backtrace).join("\n")
28
- end
29
- end
30
-
31
22
  def log_airbrake(msg_or_exception, payload)
32
23
  if defined?(Airbrake)
33
24
  if msg_or_exception.is_a?(String)
@@ -41,15 +32,12 @@ module RabbitJobs
41
32
  def report_error(error_type, *args)
42
33
  case error_type
43
34
  when :not_found
44
- log_error "Cannot find job class '#{args.first}'"
35
+ RJ.logger.error "Cannot find job class '#{args.first}'"
45
36
  when :parsing_error
46
- log_error "Cannot initialize job. Json parsing error."
47
- log_error "Data received: #{args.first.inspect}"
37
+ RJ.logger.error "Cannot initialize job. Json parsing error. Data received: #{args.first.inspect}"
48
38
  when :error
49
39
  ex, payload = args
50
- log_error "Cannot initialize job."
51
- log_error ex, payload
52
- log_error "Data received: #{payload.inspect}"
40
+ RJ.logger.error short_message: ex.message, full_message: ex.backtrace, _payload: payload.inspect
53
41
  end
54
42
  end
55
43
  end
@@ -2,15 +2,6 @@
2
2
 
3
3
  module RabbitJobs
4
4
  module Helpers
5
- def _cleanup_backtrace(trace_lines)
6
- if defined?(Rails) && Rails.respond_to?(:root)
7
- rails_root_path = Rails.root.to_s
8
- trace_lines.dup.keep_if { |l| l[rails_root_path] }
9
- else
10
- trace_lines
11
- end
12
- end
13
-
14
5
  def symbolize_keys!(hash)
15
6
  hash.inject({}) do |options, (key, value)|
16
7
  options[(key.to_sym rescue key) || key] = value
@@ -20,7 +20,7 @@ module RabbitJobs
20
20
  begin
21
21
  ret = nil
22
22
  execution_time = Benchmark.measure { ret = perform(*params) }
23
- RabbitJobs.logger.info short_message: "Job processed [ok]", _job: self.to_ruby_string, _execution_time: execution_time.to_s.strip
23
+ RabbitJobs.logger.info short_message: self.to_ruby_string, _execution_time: execution_time.to_s.strip
24
24
  rescue
25
25
  log_job_error($!)
26
26
  run_on_error_hooks($!)
@@ -35,13 +35,17 @@ module RabbitJobs
35
35
  proc = self.method(proc_or_symbol)
36
36
  end
37
37
 
38
- case proc.arity
39
- when 0
40
- proc.call()
41
- when 1
42
- proc.call(error)
43
- else
44
- proc.call(error, *params)
38
+ begin
39
+ case proc.arity
40
+ when 0
41
+ proc.call()
42
+ when 1
43
+ proc.call(error)
44
+ else
45
+ proc.call(error, *params)
46
+ end
47
+ rescue
48
+ RJ.logger.error($!)
45
49
  end
46
50
  end
47
51
  end
@@ -95,11 +99,10 @@ module RabbitJobs
95
99
  end
96
100
 
97
101
  def log_job_error(error)
98
- RabbitJobs.logger.error(short_message: "Job processed [error]",
99
- _job: self.to_ruby_string, _error: error.message, _exception: error.class, full_message: _cleanup_backtrace(error.backtrace).join("\r\n"))
102
+ RabbitJobs.logger.error(short_message: error.message,
103
+ _job: self.to_ruby_string, _exception: error.class, full_message: error.backtrace.join("\r\n"))
100
104
 
101
105
  Airbrake.notify(error, session: {args: self.to_ruby_string}) if defined?(Airbrake)
102
- RabbitJobs::ErrorMailer.report_error(self, error) rescue nil
103
106
  end
104
107
  end
105
108
 
@@ -113,14 +116,14 @@ module RabbitJobs
113
116
 
114
117
  def on_error(*hooks)
115
118
  hooks.each do |proc_or_symbol|
116
- raise ArgumentError unless proc_or_symbol && ( proc_or_symbol.is_a?(Proc) || proc_or_symbol.is_a?(Symbol) )
119
+ raise ArgumentError.new("Pass proc or symbol to on_error hook") unless proc_or_symbol && ( proc_or_symbol.is_a?(Proc) || proc_or_symbol.is_a?(Symbol) )
117
120
  @rj_on_error_hooks ||= []
118
121
  @rj_on_error_hooks << proc_or_symbol
119
122
  end
120
123
  end
121
124
 
122
125
  def queue(routing_key)
123
- raise ArgumentError unless routing_key.present?
126
+ raise ArgumentError.new("routing_key is nil") unless routing_key.present?
124
127
  @rj_queue = routing_key.to_sym
125
128
  end
126
129
 
@@ -31,7 +31,7 @@ module RabbitJobs
31
31
  def log_daemon_error(error)
32
32
  if RabbitJobs.logger
33
33
  begin
34
- RabbitJobs.logger.error [error.message, error.backtrace].flatten.join("\n")
34
+ RabbitJobs.logger.fatal error
35
35
  ensure
36
36
  abort(error.message)
37
37
  end
@@ -1,5 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  module RabbitJobs
4
- VERSION = "0.8.20"
4
+ VERSION = "0.9.0"
5
5
  end
@@ -100,7 +100,7 @@ module RabbitJobs
100
100
  @processed_count += 1
101
101
  rescue
102
102
  RabbitJobs.logger.error(short_message: $!.message,
103
- _payload: payload, _exception: $!.class, full_message: _cleanup_backtrace($!.backtrace).join("\r\n"))
103
+ _payload: payload, _exception: $!.class, full_message: $!.backtrace.join("\r\n"))
104
104
  end
105
105
  true
106
106
  else
data/spec/spec_helper.rb CHANGED
@@ -6,7 +6,6 @@ end
6
6
 
7
7
  require 'rr'
8
8
  require 'timecop'
9
- require 'action_mailer'
10
9
 
11
10
  require 'rabbit_jobs'
12
11
  require 'fixtures/jobs'
@@ -34,13 +34,6 @@ describe RabbitJobs::Consumer::JobConsumer do
34
34
  end
35
35
  end
36
36
 
37
- describe '#log_error' do
38
- it 'logs error with RJ.logger' do
39
- mock(RJ.logger).error("hello")
40
- consumer.log_error 'hello'
41
- end
42
- end
43
-
44
37
  describe '#report_error' do
45
38
  it "accepts error type :not_found" do
46
39
  lambda { consumer.report_error(:not_found, 'klass_name') }.should_not raise_error
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabbit_jobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.20
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Lazureykis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-30 00:00:00.000000000 Z
11
+ date: 2013-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -88,7 +88,6 @@ files:
88
88
  - lib/rabbit_jobs.rb
89
89
  - lib/rabbit_jobs/configuration.rb
90
90
  - lib/rabbit_jobs/consumer/job_consumer.rb
91
- - lib/rabbit_jobs/error_mailer.rb
92
91
  - lib/rabbit_jobs/helpers.rb
93
92
  - lib/rabbit_jobs/job.rb
94
93
  - lib/rabbit_jobs/main_loop.rb
@@ -107,10 +106,8 @@ files:
107
106
  - spec/integration/worker_spec.rb
108
107
  - spec/spec_helper.rb
109
108
  - spec/unit/configuration_spec.rb
110
- - spec/unit/error_mailer_spec.rb
111
109
  - spec/unit/job_consumer_spec.rb
112
110
  - spec/unit/job_spec.rb
113
- - spec/unit/mailer_spec.rb
114
111
  - spec/unit/rabbit_jobs_spec.rb
115
112
  - spec/unit/worker_spec.rb
116
113
  homepage: ''
@@ -1,49 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- module RabbitJobs
3
- class ErrorMailer
4
- class << self
5
- def enabled?
6
- defined?(ActionMailer) && config_present?
7
- end
8
-
9
- def send_letter(subject, body)
10
- letter = ActionMailer::Base.mail
11
- letter.from = RabbitJobs.config.mail_errors_from
12
- letter.to = RabbitJobs.config.mail_errors_to
13
- letter.subject = subject
14
- letter.body = body
15
-
16
- letter.deliver
17
- end
18
-
19
- def report_error(job, error = $!)
20
- return unless enabled?
21
-
22
- begin
23
- subject, text = build_error_message(job, error)
24
- send_letter(subject, text)
25
- rescue
26
- RabbitJobs.logger.error $!
27
- end
28
- end
29
-
30
- private
31
-
32
- def build_error_message(job, error)
33
- params = job.params || []
34
-
35
- params_str = params.map { |p| p.inspect }.join(', ')
36
- subject = "RJ:Worker: #{error.class} on #{job.class}"
37
- text = "\n#{job.class}.perform(#{params_str})\n"
38
- text += "\n#{error.inspect}\n"
39
- text += "\nBacktrace:\n#{error.backtrace.join("\n")}" if error.backtrace
40
- [subject, text]
41
- end
42
-
43
- def config_present?
44
- config = RabbitJobs.config
45
- config.mail_errors_from.present? && config.mail_errors_to.present?
46
- end
47
- end
48
- end
49
- end
@@ -1,14 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'spec_helper'
3
-
4
- describe RabbitJobs::ErrorMailer do
5
- describe '#report_error' do
6
- it 'logs error raised in #send_letter' do
7
- mock(RabbitJobs::ErrorMailer).enabled? { true }
8
- mock(RabbitJobs::ErrorMailer).send_letter(anything, anything) { raise 'hello' }
9
-
10
- mock(RabbitJobs.logger).error(anything)
11
- RabbitJobs::ErrorMailer.report_error(TestJob.new, StandardError.new)
12
- end
13
- end
14
- end
@@ -1,27 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'spec_helper'
3
-
4
- describe RabbitJobs::ErrorMailer do
5
- describe '#enabled?' do
6
- it 'should be enabled when use setup email' do
7
- RabbitJobs::ErrorMailer.enabled?.should == false
8
- RabbitJobs.configure do |c|
9
- c.mail_errors_to 'dev@example.com'
10
- c.mail_errors_from 'app@example.com'
11
- end
12
-
13
- RabbitJobs::ErrorMailer.enabled?.should == true
14
- end
15
- end
16
-
17
- describe '#send' do
18
- it 'should send email with error' do
19
- email = ActionMailer::Base.mail
20
- mock(ActionMailer::Base).mail { email }
21
- mock(email).deliver { }
22
- mock(RabbitJobs::ErrorMailer).enabled? { true }
23
-
24
- RabbitJobs::ErrorMailer.report_error(TestJob.new, RuntimeError.new('error text'))
25
- end
26
- end
27
- end