resque_mailer 2.2.7 → 2.3.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: bc00ecc2825ecbdfb1569db2d721e2ba1b1e7881
4
- data.tar.gz: 4c33b71e7f01d7c077ca5c90df02906dc02ff0f4
3
+ metadata.gz: fdc6b3606f8bb8c4556b38fd5ba24a0df26c8038
4
+ data.tar.gz: 26819b80f0f5e6723b1d6127ecb55d02c9c704b8
5
5
  SHA512:
6
- metadata.gz: 0b79aae5b1b79c4e6cac2f12f9084ac8df048fded91ff9ef62b58450ff95cf30cbc455a13d77f35c60d49c944d2ce08548f3fdca7d3011b0245c9230f040e88c
7
- data.tar.gz: 67c0d0c9dc358b4830dbc90aa525366df64a36d1326fd11551355f78b458d282eba89b7db42ebb72bd7ca474f0ae14f73e51c2efcddb9501869cb60de5e40811
6
+ metadata.gz: 25ede40de656bc07d969848e9492825b617c6cae6fc87bfbb6ce3b25adc36660872bfaff163db65cd6eb17e28f753acc1e496f5a839fd9285c580f871a5cdcc4
7
+ data.tar.gz: 018c91c5908466b0d0ea6c94390b65ce063b4b60895e2285a1f536c9eeead5e6eafa6b2895bcef36a4ec99b7ffe0fd00cb1d400621d3291fc9d12eea815669b8
@@ -1,3 +1,10 @@
1
+ ### 2.3.0 / 2016-04-30
2
+ * Convert specs to use modern RSpec expectation syntax
3
+ * Added argument serializers (Andrew DiMichele, René Klačan, Adam Bird)
4
+ * ActiveRecord argument serializer (René Klačan)
5
+ * Use `deliver_now` if available
6
+ * Remove deprecated fallback / error options in prep for 2.3.x
7
+
1
8
  ### 2.2.7 / 2014-10-08
2
9
  * Pass respond_to? inquiries through to decoy (to allow preview, etc)
3
10
  (Ian Lesperance)
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 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
@@ -24,9 +24,11 @@ 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
@@ -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,7 +66,7 @@ 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. There are two supported
69
+ assigning a lambda to the `error_handler` attribute. There are two supported
63
70
  lambdas for backwards compatiability.
64
71
 
65
72
  The first lamba will be deprecated in a future release:
@@ -89,18 +96,32 @@ Resque::Mailer.error_handler = lambda { |mailer, message, error, action, args|
89
96
  If you have a variety of mailers in your application and want all of them to use
90
97
  Resque::Mailer by default, you can subclass ActionMailer::Base and have your
91
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
92
114
 
93
- # config/initializers/resque_mailer.rb
94
- class AsyncMailer < ActionMailer::Base
95
- include Resque::Mailer
96
- 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.
97
121
 
98
- # app/mailers/example_mailer.rb
99
- class ExampleMailer < AsyncMailer
100
- def say_hello(user_id)
101
- # ...
102
- end
103
- 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`
104
125
 
105
126
  ### Using with Resque Scheduler
106
127
 
@@ -108,27 +129,29 @@ If [resque-scheduler](https://github.com/bvandenbos/resque-scheduler) is
108
129
  installed, two extra methods will be available: `deliver_at` and `deliver_in`.
109
130
  These will enqueue mail for delivery at a specified time in the future.
110
131
 
111
- # Delivers on the 25th of December, 2014
112
- MyMailer.reminder_email(params).deliver_at(Time.parse('2014-12-25'))
113
-
114
- # Delivers in 7 days
115
- 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'))
116
135
 
117
- # Unschedule delivery
118
- MyMailer.reminder_email(params).unschedule_delivery
136
+ # Delivers in 7 days
137
+ MyMailer.reminder_email(params).deliver_in(7.days)
119
138
 
139
+ # Unschedule delivery
140
+ MyMailer.reminder_email(params).unschedule_delivery
141
+ ```
120
142
  ## Testing
121
143
 
122
144
  You don't want to be sending actual emails in the test environment, so you can
123
145
  configure the environments that should be excluded like so:
124
-
125
- # config/initializers/resque_mailer.rb
126
- Resque::Mailer.excluded_environments = [:test, :cucumber]
146
+ ```ruby
147
+ # config/initializers/resque_mailer.rb
148
+ Resque::Mailer.excluded_environments = [:test, :cucumber]
149
+ ```
127
150
 
128
151
  Note: Define `current_env` if using Resque::Mailer in a non-Rails project:
129
-
130
- Resque::Mailer.current_env = :production
131
-
152
+ ```ruby
153
+ Resque::Mailer.current_env = :production
154
+ ```
132
155
 
133
156
  ## Note on Patches / Pull Requests
134
157
 
@@ -1,9 +1,12 @@
1
1
  require 'resque_mailer/version'
2
+ require 'resque_mailer/serializers/pass_thru_serializer'
3
+ require 'resque_mailer/serializers/active_record_serializer'
2
4
 
3
5
  module Resque
4
6
  module Mailer
5
7
  class << self
6
8
  attr_accessor :default_queue_name, :default_queue_target, :current_env, :logger, :error_handler
9
+ attr_accessor :argument_serializer
7
10
  attr_reader :excluded_environments
8
11
 
9
12
  def excluded_environments=(envs)
@@ -13,17 +16,13 @@ module Resque
13
16
  def included(base)
14
17
  base.extend(ClassMethods)
15
18
  end
16
-
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"
20
- end
21
19
  end
22
20
 
23
21
  self.logger ||= (defined?(Rails) ? Rails.logger : nil)
24
22
  self.default_queue_target = ::Resque
25
23
  self.default_queue_name = "mailer"
26
24
  self.excluded_environments = [:test]
25
+ self.argument_serializer = ::Resque::Mailer::Serializers::PassThruSerializer
27
26
 
28
27
  module ClassMethods
29
28
 
@@ -43,18 +42,18 @@ module Resque
43
42
  end
44
43
  end
45
44
 
46
- def perform(action, *args)
45
+ def perform(action, serialized_args)
47
46
  begin
47
+ args = ::Resque::Mailer.argument_serializer.deserialize(serialized_args)
48
48
  message = self.send(:new, action, *args).message
49
- message.deliver
49
+ if message.respond_to?(:deliver_now)
50
+ message.deliver_now
51
+ else
52
+ message.deliver
53
+ end
50
54
  rescue Exception => ex
51
55
  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
56
+ Mailer.error_handler.call(self, message, ex, action, args)
58
57
  else
59
58
  if logger
60
59
  logger.error "Unable to deliver email [#{action}]: #{ex}"
@@ -94,6 +93,7 @@ module Resque
94
93
  @mailer_class = mailer_class
95
94
  @method_name = method_name
96
95
  *@args = *args
96
+ @serialized_args = ::Resque::Mailer.argument_serializer.serialize(*args)
97
97
  actual_message if environment_excluded?
98
98
  end
99
99
 
@@ -126,7 +126,7 @@ module Resque
126
126
 
127
127
  if @mailer_class.deliver?
128
128
  begin
129
- resque.enqueue(@mailer_class, @method_name, *@args)
129
+ resque.enqueue(@mailer_class, @method_name, @serialized_args)
130
130
  rescue Errno::ECONNREFUSED, Redis::CannotConnectError
131
131
  logger.error "Unable to connect to Redis; falling back to synchronous mail delivery" if logger
132
132
  deliver!
@@ -167,7 +167,11 @@ module Resque
167
167
  end
168
168
 
169
169
  def deliver!
170
- actual_message.deliver
170
+ if actual_message.respond_to?(:deliver_now)
171
+ actual_message.deliver_now
172
+ else
173
+ actual_message.deliver
174
+ end
171
175
  end
172
176
 
173
177
  def method_missing(method_name, *args)
@@ -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.7"
3
+ VERSION = "2.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.7
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Plante
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-08 00:00:00.000000000 Z
11
+ date: 2016-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.0'
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
26
  version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '2.6'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.6'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: yard
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: 0.6.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.6.0
55
55
  description: Rails plugin for sending asynchronous email with ActionMailer and Resque.
@@ -66,6 +66,8 @@ files:
66
66
  - LICENSE
67
67
  - README.md
68
68
  - lib/resque_mailer.rb
69
+ - lib/resque_mailer/serializers/active_record_serializer.rb
70
+ - lib/resque_mailer/serializers/pass_thru_serializer.rb
69
71
  - lib/resque_mailer/version.rb
70
72
  homepage: http://github.com/zapnap/resque_mailer
71
73
  licenses:
@@ -77,17 +79,17 @@ require_paths:
77
79
  - lib
78
80
  required_ruby_version: !ruby/object:Gem::Requirement
79
81
  requirements:
80
- - - '>='
82
+ - - ">="
81
83
  - !ruby/object:Gem::Version
82
84
  version: '0'
83
85
  required_rubygems_version: !ruby/object:Gem::Requirement
84
86
  requirements:
85
- - - '>='
87
+ - - ">="
86
88
  - !ruby/object:Gem::Version
87
89
  version: '0'
88
90
  requirements: []
89
91
  rubyforge_project:
90
- rubygems_version: 2.2.2
92
+ rubygems_version: 2.5.1
91
93
  signing_key:
92
94
  specification_version: 4
93
95
  summary: Rails plugin for sending asynchronous email with ActionMailer and Resque.