resque_mailer 2.2.6 → 2.4.3

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: 53a54447608a2968256ef39072f6308d1dbc2169
4
- data.tar.gz: e9ff62895bacee201cca55e7f3cb5ed805302cb4
3
+ metadata.gz: 548d9708f6b7a14a37327ffb46f45576582ec6bf
4
+ data.tar.gz: 9e8be7d64d9ec61fe8b5448a1b7e5ab79ceb47a0
5
5
  SHA512:
6
- metadata.gz: c49ea092064b92528689c38ac49eac32d1c0f451c4e56701a27ac0b3c713609d9bd6daaf1b0e1d6e2245c05168f2ae2dd84fa979d4ba6dfe7f06dca4fdf14de4
7
- data.tar.gz: 6be3cbf5e72deba7c4950f22f01effb46e0c6f2a7a20a02b83eaca5be5218166f7bfead4ae8ed75b4050a7359b502091c2b4b192f2be0cb363fb54470da42c94
6
+ metadata.gz: 94c591b3103a3f56ba56243da5858cd18ef6666dfe15018298081d93de71e270426e76985f6fd4a62fbb1a8d1a13ad76a50404c8045261c5b185e94d74d882ee
7
+ data.tar.gz: 9f580508433f12a0c4ab1ba66ccbda30efd4e23cc27e82b5e6abe3183c8b4b32fa80d366e3939447f31407725c43c621652ed19f801b755b40e7b31c3c87f61a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
- ### EDGE / 2013-11-12
2
- * Add action and args as arguments to the error handler lambda for
1
+ ### 2.4.3 / 2017-09-18
2
+ * Fix for duplicated keys (J Garcia)
3
+
4
+ ### 2.4.2 / 2017-01-30
5
+ * Fix for breaking change with symbolied keys vs strings (J Garcia)
6
+
7
+ ### 2.4.1 / 2016-12-10
8
+ * Symbolize argument keys to fix mailer block syntax issues (J Garcia)
9
+ * Alias method for `deliver_now` (Kurt Funai)
10
+
11
+ ### 2.4.0 / 2016-10-05
12
+ * Rails 5 compatibility
13
+
14
+ ### 2.3.1 / 2016-07-03
15
+ * Serializer bugfix for scheduler integration
16
+ * RSpec cleanup
17
+
18
+ ### 2.3.0 / 2016-04-30
19
+ * Convert specs to use modern RSpec expectation syntax
20
+ * Added argument serializers (Andrew DiMichele, René Klačan, Adam Bird)
21
+ * ActiveRecord argument serializer (René Klačan)
22
+ * Use `deliver_now` if available
23
+ * Remove deprecated fallback / error options in prep for 2.3.x
24
+
25
+ ### 2.2.7 / 2014-10-08
26
+ * Pass respond_to? inquiries through to decoy (to allow preview, etc)
27
+ (Ian Lesperance)
28
+
29
+ ### 2.2.6 / 2013-11-13
30
+ * Add action and args as arguments to the error handler lambda for
3
31
  requeuing (Ellis Berner, Austen Ito)
4
32
  * Redis client v3 support; fix unhandled exception when offline
5
33
  (Yoav Matchulsky)
@@ -7,13 +35,13 @@
7
35
  ### 2.2.5 / 2013-10-10
8
36
  * Travis Integration (Peter Goldstein)
9
37
  * ActionMailer 4.0 test compatibility (Peter Goldstein)
10
- * Added `unschedule_delivery` method for resque-scheduler integration
38
+ * Added `unschedule_delivery` method for resque-scheduler integration
11
39
  (gsdean)
12
40
 
13
41
  ### 2.2.4 / 2013-05-25
14
42
  * Compatibility for Rails 4 pre-release (Ben Woosley)
15
43
  * Fallback to synchronous is default when connection to Redis fails
16
- * Avoid lazy evaluation of mail when excluded, for use with mail_view
44
+ * Avoid lazy evaluation of mail when excluded, for use with mail_view
17
45
  (gingerlime)
18
46
 
19
47
  ### 2.2.3 / 2013-02-27
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Nick Plante
1
+ Copyright (c) 2016 Nick Plante
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -6,7 +6,7 @@ A gem plugin which allows messages prepared by ActionMailer to be delivered
6
6
  asynchronously. Assumes you're using [Resque](https://github.com/resque/resque)
7
7
  for your background jobs.
8
8
 
9
- Note that recent (2.0+) versions of Resque::Mailer only work with Rails 3.x or 4.x.
9
+ Note that recent (2.0+) versions of Resque::Mailer only work with Rails 3.x or later.
10
10
  For a version compatible with Rails 2, specify v1.x in your Gemfile.
11
11
 
12
12
  ## Installation
@@ -24,13 +24,15 @@ If you're using Bundler to manage your dependencies, you should add it to your G
24
24
 
25
25
  Include Resque::Mailer in your ActionMailer subclass(es) like this:
26
26
 
27
- class MyMailer < ActionMailer::Base
28
- include Resque::Mailer
29
- end
27
+ ```ruby
28
+ class MyMailer < ActionMailer::Base
29
+ include Resque::Mailer
30
+ end
31
+ ```
30
32
 
31
33
  Now, when `MyMailer.subject_email(params).deliver` is called, an entry
32
34
  will be created in the job queue. Your Resque workers will be able to deliver
33
- this message for you. The queue we're using is imaginatively named +mailer+,
35
+ this message for you. The queue we're using is imaginatively named `mailer`,
34
36
  so just make sure your workers know about it and are loading your environment:
35
37
 
36
38
  QUEUE=mailer rake environment resque:work
@@ -38,19 +40,24 @@ so just make sure your workers know about it and are loading your environment:
38
40
  Note that you can still have mail delivered synchronously by using the bang
39
41
  method variant:
40
42
 
41
- MyMailer.subject_email(params).deliver!
43
+ ```ruby
44
+ MyMailer.subject_email(params).deliver!
45
+ ```
42
46
 
43
47
  Oh, by the way. Don't forget that **your async mailer jobs will be processed by
44
48
  a separate worker**. This means that you should resist the temptation to pass
45
49
  database-backed objects as parameters in your mailer and instead pass record
46
50
  identifiers. Then, in your delivery method, you can look up the record from
47
- the id and use it as needed.
51
+ the id and use it as needed. If you'd like, you can write your own serializer
52
+ to automate such things; see the section on serializers below.
48
53
 
49
54
  If you want to set a different default queue name for your mailer, you can
50
55
  change the `default_queue_name` property like so:
51
56
 
52
- # config/initializers/resque_mailer.rb
53
- Resque::Mailer.default_queue_name = 'application_specific_mailer'
57
+ ```ruby
58
+ # config/initializers/resque_mailer.rb
59
+ Resque::Mailer.default_queue_name = 'application_specific_mailer'
60
+ ```
54
61
 
55
62
  This is useful when you are running more than one application using
56
63
  resque_mailer in a shared environment. You will need to use the new queue
@@ -59,9 +66,8 @@ name when starting your workers.
59
66
  QUEUE=application_specific_mailer rake environment resque:work
60
67
 
61
68
  Custom handling of errors that arise when sending a message is possible by
62
- assigning a lambda to the `error_hander` attribute.
63
-
64
- There are two supported lambdas for backwards compatiability:
69
+ assigning a lambda to the `error_handler` attribute. There are two supported
70
+ lambdas for backwards compatiability.
65
71
 
66
72
  The first lamba will be deprecated in a future release:
67
73
 
@@ -77,10 +83,10 @@ mailers to be requeued on failure:
77
83
  ```ruby
78
84
  Resque::Mailer.error_handler = lambda { |mailer, message, error, action, args|
79
85
  # Necessary to re-enqueue jobs that receieve the SIGTERM signal
80
- if exception.is_a?(Resque::TermException)
86
+ if error.is_a?(Resque::TermException)
81
87
  Resque.enqueue(mailer, action, *args)
82
88
  else
83
- raise exception
89
+ raise error
84
90
  end
85
91
  }
86
92
  ```
@@ -90,18 +96,32 @@ Resque::Mailer.error_handler = lambda { |mailer, message, error, action, args|
90
96
  If you have a variety of mailers in your application and want all of them to use
91
97
  Resque::Mailer by default, you can subclass ActionMailer::Base and have your
92
98
  other mailers inherit from an AsyncMailer:
99
+ ```ruby
100
+ # config/initializers/resque_mailer.rb
101
+ class AsyncMailer < ActionMailer::Base
102
+ include Resque::Mailer
103
+ end
104
+
105
+ # app/mailers/example_mailer.rb
106
+ class ExampleMailer < AsyncMailer
107
+ def say_hello(user_id)
108
+ # ...
109
+ end
110
+ end
111
+ ```
112
+
113
+ ### Writing an Argument Serializer
93
114
 
94
- # config/initializers/resque_mailer.rb
95
- class AsyncMailer < ActionMailer::Base
96
- include Resque::Mailer
97
- end
115
+ By default, the arguments you pass to your mailer are passed as-is to Resque. This
116
+ means you cannot pass things like database-backed objects. If you'd like to write
117
+ your own serializer to enable such things, simply write a class that implements
118
+ the class methods `self.serialize(*args)` and `self.deserialize(data)` and set
119
+ `Resque::Mailer.argument_serializer = YourSerializerClass` in your resque_mailer
120
+ initializer.
98
121
 
99
- # app/mailers/example_mailer.rb
100
- class ExampleMailer < AsyncMailer
101
- def say_hello(user)
102
- # ...
103
- end
104
- end
122
+ There's also Active Record serializer which allows you to pass AR
123
+ models directly as arguments. To use it just do:
124
+ `Resque::Mailer.argument_serializer = Resque::Mailer::Serializers::ActiveRecordSerializer`
105
125
 
106
126
  ### Using with Resque Scheduler
107
127
 
@@ -109,27 +129,29 @@ If [resque-scheduler](https://github.com/bvandenbos/resque-scheduler) is
109
129
  installed, two extra methods will be available: `deliver_at` and `deliver_in`.
110
130
  These will enqueue mail for delivery at a specified time in the future.
111
131
 
112
- # Delivers on the 25th of December, 2013
113
- MyMailer.reminder_email(params).deliver_at(Time.parse('2013-12-25'))
114
-
115
- # Delivers in 7 days
116
- MyMailer.reminder_email(params).deliver_in(7.days)
132
+ ```ruby
133
+ # Delivers on the 25th of December, 2014
134
+ MyMailer.reminder_email(params).deliver_at(Time.parse('2014-12-25'))
117
135
 
118
- # Unschedule delivery
119
- MyMailer.reminder_email(params).unschedule_delivery
136
+ # Delivers in 7 days
137
+ MyMailer.reminder_email(params).deliver_in(7.days)
120
138
 
139
+ # Unschedule delivery
140
+ MyMailer.reminder_email(params).unschedule_delivery
141
+ ```
121
142
  ## Testing
122
143
 
123
144
  You don't want to be sending actual emails in the test environment, so you can
124
145
  configure the environments that should be excluded like so:
125
-
126
- # config/initializers/resque_mailer.rb
127
- Resque::Mailer.excluded_environments = [:test, :cucumber]
146
+ ```ruby
147
+ # config/initializers/resque_mailer.rb
148
+ Resque::Mailer.excluded_environments = [:test, :cucumber]
149
+ ```
128
150
 
129
151
  Note: Define `current_env` if using Resque::Mailer in a non-Rails project:
130
-
131
- Resque::Mailer.current_env = :production
132
-
152
+ ```ruby
153
+ Resque::Mailer.current_env = :production
154
+ ```
133
155
 
134
156
  ## Note on Patches / Pull Requests
135
157
 
@@ -0,0 +1,29 @@
1
+ module Resque
2
+ module Mailer
3
+ module Serializers
4
+ module ActiveRecordSerializer
5
+ extend self
6
+
7
+ def serialize(*args)
8
+ args.map do |arg|
9
+ if arg.is_a?(ActiveRecord::Base)
10
+ { "class_name" => arg.class.name, "id" => arg.id }
11
+ else
12
+ arg
13
+ end
14
+ end
15
+ end
16
+
17
+ def deserialize(data)
18
+ data.map do |arg|
19
+ if arg.is_a?(Hash) && arg.has_key?("class_name") && arg.has_key?("id")
20
+ arg["class_name"].constantize.find(arg["id"])
21
+ else
22
+ arg
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+ module Resque
2
+ module Mailer
3
+ module Serializers
4
+
5
+ # Simple serializer for Resque arguments
6
+ # New serializers need only implement the self.serialize(*args) and self.deserialize(data)
7
+ # * self.serialize(*args) should return the arguments serialized as an object
8
+ # * self.deserialize(data) should take the serialized object as its only argument and return the array of arguments
9
+
10
+ module PassThruSerializer
11
+ extend self
12
+
13
+ def serialize(*args)
14
+ args
15
+ end
16
+
17
+ def deserialize(data)
18
+ data
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  module Resque
2
2
  module Mailer
3
- VERSION = "2.2.6"
3
+ VERSION = "2.4.3"
4
4
  end
5
5
  end
data/lib/resque_mailer.rb CHANGED
@@ -1,22 +1,27 @@
1
1
  require 'resque_mailer/version'
2
+ require 'resque_mailer/serializers/pass_thru_serializer'
3
+ require 'resque_mailer/serializers/active_record_serializer'
4
+ require 'active_support/core_ext/hash'
2
5
 
3
6
  module Resque
4
7
  module Mailer
5
8
  class << self
6
9
  attr_accessor :default_queue_name, :default_queue_target, :current_env, :logger, :error_handler
10
+ attr_accessor :argument_serializer
7
11
  attr_reader :excluded_environments
8
12
 
9
13
  def excluded_environments=(envs)
10
14
  @excluded_environments = [*envs].map { |e| e.to_sym }
11
15
  end
12
16
 
13
- def included(base)
14
- base.extend(ClassMethods)
17
+ def prepare_message(klass, action, *args)
18
+ msg = klass.send(:new)
19
+ msg.process(action, *args)
20
+ msg.message
15
21
  end
16
22
 
17
- # Deprecated
18
- def fallback_to_synchronous=(val)
19
- warn "WARNING: fallback_to_synchronous option is deprecated and will be removed in the next release"
23
+ def included(base)
24
+ base.extend(ClassMethods)
20
25
  end
21
26
  end
22
27
 
@@ -24,6 +29,7 @@ module Resque
24
29
  self.default_queue_target = ::Resque
25
30
  self.default_queue_name = "mailer"
26
31
  self.excluded_environments = [:test]
32
+ self.argument_serializer = ::Resque::Mailer::Serializers::PassThruSerializer
27
33
 
28
34
  module ClassMethods
29
35
 
@@ -43,18 +49,24 @@ module Resque
43
49
  end
44
50
  end
45
51
 
46
- def perform(action, *args)
52
+ def perform(action, serialized_args)
47
53
  begin
48
- message = self.send(:new, action, *args).message
49
- message.deliver
54
+ args = ::Resque::Mailer.argument_serializer.deserialize(serialized_args)
55
+ # Set hash as hash with indifferent access so mailer block syntax (needs symbols) works
56
+ if args.is_a?(Array)
57
+ args = args.each_with_object([]) do |arg, o|
58
+ o << (arg.is_a?(Hash) ? arg.with_indifferent_access : arg)
59
+ end
60
+ end
61
+ message = ::Resque::Mailer.prepare_message(self, action, *args)
62
+ if message.respond_to?(:deliver_now)
63
+ message.deliver_now
64
+ else
65
+ message.deliver
66
+ end
50
67
  rescue Exception => ex
51
68
  if Mailer.error_handler
52
- if Mailer.error_handler.arity == 3
53
- warn "WARNING: error handlers with 3 arguments are deprecated and will be removed in the next release"
54
- Mailer.error_handler.call(self, message, ex)
55
- else
56
- Mailer.error_handler.call(self, message, ex, action, args)
57
- end
69
+ Mailer.error_handler.call(self, message, ex, action, args)
58
70
  else
59
71
  if logger
60
72
  logger.error "Unable to deliver email [#{action}]: #{ex}"
@@ -94,6 +106,7 @@ module Resque
94
106
  @mailer_class = mailer_class
95
107
  @method_name = method_name
96
108
  *@args = *args
109
+ @serialized_args = ::Resque::Mailer.argument_serializer.serialize(*args)
97
110
  actual_message if environment_excluded?
98
111
  end
99
112
 
@@ -118,7 +131,7 @@ module Resque
118
131
  end
119
132
 
120
133
  def actual_message
121
- @actual_message ||= @mailer_class.send(:new, @method_name, *@args).message
134
+ @actual_message ||= ::Resque::Mailer.prepare_message(@mailer_class, @method_name, *@args)
122
135
  end
123
136
 
124
137
  def deliver
@@ -126,13 +139,14 @@ module Resque
126
139
 
127
140
  if @mailer_class.deliver?
128
141
  begin
129
- resque.enqueue(@mailer_class, @method_name, *@args)
142
+ resque.enqueue(@mailer_class, @method_name, @serialized_args)
130
143
  rescue Errno::ECONNREFUSED, Redis::CannotConnectError
131
144
  logger.error "Unable to connect to Redis; falling back to synchronous mail delivery" if logger
132
145
  deliver!
133
146
  end
134
147
  end
135
148
  end
149
+ alias_method :deliver_now, :deliver
136
150
 
137
151
  def deliver_at(time)
138
152
  return deliver! if environment_excluded?
@@ -142,7 +156,7 @@ module Resque
142
156
  end
143
157
 
144
158
  if @mailer_class.deliver?
145
- resque.enqueue_at(time, @mailer_class, @method_name, *@args)
159
+ resque.enqueue_at(time, @mailer_class, @method_name, @serialized_args)
146
160
  end
147
161
  end
148
162
 
@@ -154,7 +168,7 @@ module Resque
154
168
  end
155
169
 
156
170
  if @mailer_class.deliver?
157
- resque.enqueue_in(time, @mailer_class, @method_name, *@args)
171
+ resque.enqueue_in(time, @mailer_class, @method_name, @serialized_args)
158
172
  end
159
173
  end
160
174
 
@@ -163,17 +177,26 @@ module Resque
163
177
  raise "You need to install resque-scheduler to use unschedule_delivery"
164
178
  end
165
179
 
166
- resque.remove_delayed(@mailer_class, @method_name, *@args)
180
+ resque.remove_delayed(@mailer_class, @method_name, @serialized_args)
167
181
  end
168
182
 
169
183
  def deliver!
170
- actual_message.deliver
184
+ if actual_message.respond_to?(:deliver_now)
185
+ actual_message.deliver_now
186
+ else
187
+ actual_message.deliver
188
+ end
171
189
  end
190
+ alias_method :deliver_now!, :deliver!
172
191
 
173
192
  def method_missing(method_name, *args)
174
193
  actual_message.send(method_name, *args)
175
194
  end
176
195
 
196
+ def respond_to?(method_name, *args)
197
+ super || actual_message.respond_to?(method_name, *args)
198
+ end
199
+
177
200
  def logger
178
201
  @mailer_class.logger
179
202
  end
metadata CHANGED
@@ -1,55 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.6
4
+ version: 2.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Plante
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-13 00:00:00.000000000 Z
11
+ date: 2017-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: actionmailer
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - '>='
31
+ - - ">="
18
32
  - !ruby/object:Gem::Version
19
33
  version: '3.0'
20
34
  type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - '>='
38
+ - - ">="
25
39
  - !ruby/object:Gem::Version
26
40
  version: '3.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rspec
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ~>
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '2.6'
47
+ version: '3.5'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ~>
52
+ - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '2.6'
54
+ version: '3.5'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: yard
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - '>='
59
+ - - ">="
46
60
  - !ruby/object:Gem::Version
47
61
  version: 0.6.0
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - '>='
66
+ - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: 0.6.0
55
69
  description: Rails plugin for sending asynchronous email with ActionMailer and Resque.
@@ -62,13 +76,16 @@ extra_rdoc_files:
62
76
  - CHANGELOG.md
63
77
  - README.md
64
78
  files:
65
- - lib/resque_mailer/version.rb
66
- - lib/resque_mailer.rb
67
- - README.md
68
- - LICENSE
69
79
  - CHANGELOG.md
80
+ - LICENSE
81
+ - README.md
82
+ - lib/resque_mailer.rb
83
+ - lib/resque_mailer/serializers/active_record_serializer.rb
84
+ - lib/resque_mailer/serializers/pass_thru_serializer.rb
85
+ - lib/resque_mailer/version.rb
70
86
  homepage: http://github.com/zapnap/resque_mailer
71
- licenses: []
87
+ licenses:
88
+ - MIT
72
89
  metadata: {}
73
90
  post_install_message:
74
91
  rdoc_options: []
@@ -76,19 +93,18 @@ require_paths:
76
93
  - lib
77
94
  required_ruby_version: !ruby/object:Gem::Requirement
78
95
  requirements:
79
- - - '>='
96
+ - - ">="
80
97
  - !ruby/object:Gem::Version
81
98
  version: '0'
82
99
  required_rubygems_version: !ruby/object:Gem::Requirement
83
100
  requirements:
84
- - - '>='
101
+ - - ">="
85
102
  - !ruby/object:Gem::Version
86
103
  version: '0'
87
104
  requirements: []
88
105
  rubyforge_project:
89
- rubygems_version: 2.0.3
106
+ rubygems_version: 2.6.13
90
107
  signing_key:
91
108
  specification_version: 4
92
109
  summary: Rails plugin for sending asynchronous email with ActionMailer and Resque.
93
110
  test_files: []
94
- has_rdoc: