resque_mailer 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ### 2.2.1 / 2012-12-09
2
+ * Added optional support for synchronous fallback (Lee Edwards and
3
+ Peter Jaros)
4
+ * Added optional custom error_handler lambda support (Adam Bird)
5
+
1
6
  ### 2.2.0 / 2012-12-01
2
7
  * Added logging for failed deliveries (Mike Swieton)
3
8
  * Fixed / preserved exceptions for template renders (Sidharth Shanker)
data/README.md CHANGED
@@ -45,6 +45,15 @@ name when starting your workers.
45
45
 
46
46
  QUEUE=application_specific_mailer rake environment resque:work
47
47
 
48
+ Custom handling of errors that arise when sending a message is possible by
49
+ assigning a lambda to the `error_hander` attribute.
50
+
51
+ ```ruby
52
+ Resque::Mailer.error_handler = lambda { |mailer, message, error|
53
+ # some custom error handling code here in which you optionally re-raise the error
54
+ }
55
+ ```
56
+
48
57
  ### Using with Resque Scheduler
49
58
 
50
59
  If [resque-scheduler](https://github.com/bvandenbos/resque-scheduler) is
data/lib/resque_mailer.rb CHANGED
@@ -3,7 +3,7 @@ require 'resque_mailer/version'
3
3
  module Resque
4
4
  module Mailer
5
5
  class << self
6
- attr_accessor :default_queue_name, :default_queue_target, :current_env, :logger
6
+ attr_accessor :default_queue_name, :default_queue_target, :current_env, :logger, :fallback_to_synchronous, :error_handler
7
7
  attr_reader :excluded_environments
8
8
 
9
9
  def excluded_environments=(envs)
@@ -21,6 +21,7 @@ module Resque
21
21
  self.excluded_environments = [:test]
22
22
 
23
23
  module ClassMethods
24
+
24
25
  def current_env
25
26
  if defined?(Rails)
26
27
  ::Resque::Mailer.current_env || ::Rails.env
@@ -39,14 +40,19 @@ module Resque
39
40
 
40
41
  def perform(action, *args)
41
42
  begin
42
- self.send(:new, action, *args).message.deliver
43
+ message = self.send(:new, action, *args).message
44
+ message.deliver
43
45
  rescue Exception => ex
44
- if logger
45
- logger.error "Unable to deliver email [#{action}]: #{ex}"
46
- logger.error ex.backtrace.join("\n\t")
46
+ if Mailer.error_handler
47
+ Mailer.error_handler.call(self, message, ex)
48
+ else
49
+ if logger
50
+ logger.error "Unable to deliver email [#{action}]: #{ex}"
51
+ logger.error ex.backtrace.join("\n\t")
52
+ end
53
+
54
+ raise ex
47
55
  end
48
-
49
- raise ex
50
56
  end
51
57
  end
52
58
 
@@ -104,7 +110,11 @@ module Resque
104
110
  return deliver! if environment_excluded?
105
111
 
106
112
  if @mailer_class.deliver?
107
- resque.enqueue(@mailer_class, @method_name, *@args)
113
+ begin
114
+ resque.enqueue(@mailer_class, @method_name, *@args)
115
+ rescue Errno::ECONNREFUSED
116
+ deliver!
117
+ end
108
118
  end
109
119
  end
110
120
 
@@ -1,5 +1,5 @@
1
1
  module Resque
2
2
  module Mailer
3
- VERSION = "2.2.0"
3
+ VERSION = "2.2.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-01 00:00:00.000000000 Z
12
+ date: 2012-12-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionmailer
@@ -88,7 +88,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
88
  version: '0'
89
89
  segments:
90
90
  - 0
91
- hash: 1935343156117809086
91
+ hash: 1530888517799059977
92
92
  required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  none: false
94
94
  requirements:
@@ -97,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  version: '0'
98
98
  segments:
99
99
  - 0
100
- hash: 1935343156117809086
100
+ hash: 1530888517799059977
101
101
  requirements: []
102
102
  rubyforge_project:
103
103
  rubygems_version: 1.8.24