resque_mailer 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +7 -1
- data/README.md +21 -3
- data/lib/resque_mailer.rb +50 -8
- data/lib/resque_mailer/version.rb +1 -1
- metadata +63 -73
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
### 2.
|
1
|
+
### 2.2.0 / 2012-12-01
|
2
|
+
* Added logging for failed deliveries (Mike Swieton)
|
3
|
+
* Fixed / preserved exceptions for template renders (Sidharth Shanker)
|
4
|
+
* Add `deliver_at` and `deliver_in` methods for scheduling mail in the
|
5
|
+
future if resque-scheduler is installed (Harry Marr)
|
6
|
+
|
7
|
+
### 2.1.0 / 2012-06-09
|
2
8
|
|
3
9
|
* Message decoy acts more like a real message (to\_s)
|
4
10
|
* Removed jeweler as a dependency (managing gem directly via Bundler)
|
data/README.md
CHANGED
@@ -15,7 +15,7 @@ Include Resque::Mailer in your ActionMailer subclass(es) like this:
|
|
15
15
|
include Resque::Mailer
|
16
16
|
end
|
17
17
|
|
18
|
-
Now, when
|
18
|
+
Now, when `MyMailer.subject_email(params).deliver` is called, an entry
|
19
19
|
will be created in the job queue. Your Resque workers will be able to deliver
|
20
20
|
this message for you. The queue we're using is imaginatively named +mailer+,
|
21
21
|
so just make sure your workers know about it and are loading your environment:
|
@@ -33,8 +33,8 @@ database-backed objects as parameters in your mailer and instead pass record
|
|
33
33
|
identifiers. Then, in your delivery method, you can look up the record from
|
34
34
|
the id and use it as needed.
|
35
35
|
|
36
|
-
If you want to set a different default queue name for your mailer, you can
|
37
|
-
change the
|
36
|
+
If you want to set a different default queue name for your mailer, you can
|
37
|
+
change the `default_queue_name` property like so:
|
38
38
|
|
39
39
|
# config/initializers/resque_mailer.rb
|
40
40
|
Resque::Mailer.default_queue_name = 'application_specific_mailer'
|
@@ -45,6 +45,19 @@ name when starting your workers.
|
|
45
45
|
|
46
46
|
QUEUE=application_specific_mailer rake environment resque:work
|
47
47
|
|
48
|
+
### Using with Resque Scheduler
|
49
|
+
|
50
|
+
If [resque-scheduler](https://github.com/bvandenbos/resque-scheduler) is
|
51
|
+
installed, two extra methods will be available: `deliver_at` and `deliver_in`.
|
52
|
+
These will enqueue mail for delivery at a specified time in the future.
|
53
|
+
|
54
|
+
# Delivers on the 25th of December, 2013
|
55
|
+
MyMailer.reminder_email(params).deliver_at(Time.parse('2013-12-25'))
|
56
|
+
|
57
|
+
# Delivers in 7 days
|
58
|
+
MyMailer.reminder_email(params).deliver_in(7.days)
|
59
|
+
|
60
|
+
|
48
61
|
## Resque::Mailer as a Project Default
|
49
62
|
|
50
63
|
If you have a variety of mailers in your application and want all of them to use
|
@@ -81,6 +94,11 @@ configure the environments that should be excluded like so:
|
|
81
94
|
# config/initializers/resque_mailer.rb
|
82
95
|
Resque::Mailer.excluded_environments = [:test, :cucumber]
|
83
96
|
|
97
|
+
Note: Define `current_env` if using Resque::Mailer in a non-Rails project:
|
98
|
+
|
99
|
+
Resque::Mailer.current_env = :production
|
100
|
+
|
101
|
+
|
84
102
|
## Note on Patches / Pull Requests
|
85
103
|
|
86
104
|
* Fork the project.
|
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
|
6
|
+
attr_accessor :default_queue_name, :default_queue_target, :current_env, :logger
|
7
7
|
attr_reader :excluded_environments
|
8
8
|
|
9
9
|
def excluded_environments=(envs)
|
@@ -15,6 +15,7 @@ module Resque
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
self.logger = nil
|
18
19
|
self.default_queue_target = ::Resque
|
19
20
|
self.default_queue_name = "mailer"
|
20
21
|
self.excluded_environments = [:test]
|
@@ -29,8 +30,6 @@ module Resque
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def method_missing(method_name, *args)
|
32
|
-
return super if environment_excluded?
|
33
|
-
|
34
33
|
if action_methods.include?(method_name.to_s)
|
35
34
|
MessageDecoy.new(self, method_name, *args)
|
36
35
|
else
|
@@ -39,11 +38,16 @@ module Resque
|
|
39
38
|
end
|
40
39
|
|
41
40
|
def perform(action, *args)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
begin
|
42
|
+
self.send(:new, action, *args).message.deliver
|
43
|
+
rescue Exception => ex
|
44
|
+
if logger
|
45
|
+
logger.error "Unable to deliver email [#{action}]: #{ex}"
|
46
|
+
logger.error ex.backtrace.join("\n\t")
|
47
|
+
end
|
48
|
+
|
49
|
+
raise ex
|
50
|
+
end
|
47
51
|
end
|
48
52
|
|
49
53
|
def queue
|
@@ -80,16 +84,54 @@ module Resque
|
|
80
84
|
::Resque::Mailer.default_queue_target
|
81
85
|
end
|
82
86
|
|
87
|
+
def current_env
|
88
|
+
::Rails.env
|
89
|
+
end
|
90
|
+
|
91
|
+
def environment_excluded?
|
92
|
+
!ActionMailer::Base.perform_deliveries || excluded_environment?(current_env)
|
93
|
+
end
|
94
|
+
|
95
|
+
def excluded_environment?(name)
|
96
|
+
::Resque::Mailer.excluded_environments && ::Resque::Mailer.excluded_environments.include?(name.to_sym)
|
97
|
+
end
|
98
|
+
|
83
99
|
def actual_message
|
84
100
|
@actual_message ||= @mailer_class.send(:new, @method_name, *@args).message
|
85
101
|
end
|
86
102
|
|
87
103
|
def deliver
|
104
|
+
return deliver! if environment_excluded?
|
105
|
+
|
88
106
|
if @mailer_class.deliver?
|
89
107
|
resque.enqueue(@mailer_class, @method_name, *@args)
|
90
108
|
end
|
91
109
|
end
|
92
110
|
|
111
|
+
def deliver_at(time)
|
112
|
+
return deliver! if environment_excluded?
|
113
|
+
|
114
|
+
unless resque.respond_to? :enqueue_at
|
115
|
+
raise "You need to install resque-scheduler to use deliver_at"
|
116
|
+
end
|
117
|
+
|
118
|
+
if @mailer_class.deliver?
|
119
|
+
resque.enqueue_at(time, @mailer_class, @method_name, *@args)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def deliver_in(time)
|
124
|
+
return deliver! if environment_excluded?
|
125
|
+
|
126
|
+
unless resque.respond_to? :enqueue_in
|
127
|
+
raise "You need to install resque-scheduler to use deliver_in"
|
128
|
+
end
|
129
|
+
|
130
|
+
if @mailer_class.deliver?
|
131
|
+
resque.enqueue_in(time, @mailer_class, @method_name, *@args)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
93
135
|
def deliver!
|
94
136
|
actual_message.deliver!
|
95
137
|
end
|
metadata
CHANGED
@@ -1,80 +1,74 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque_mailer
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.2.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 2
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 2.1.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Nick Plante
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
date: 2012-12-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: actionmailer
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
22
17
|
none: false
|
23
|
-
requirements:
|
18
|
+
requirements:
|
24
19
|
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
|
27
|
-
segments:
|
28
|
-
- 3
|
29
|
-
- 0
|
30
|
-
version: "3.0"
|
31
|
-
requirement: *id001
|
32
|
-
prerelease: false
|
33
|
-
name: actionmailer
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
34
22
|
type: :runtime
|
35
|
-
|
36
|
-
version_requirements:
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
25
|
none: false
|
38
|
-
requirements:
|
26
|
+
requirements:
|
39
27
|
- - ~>
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
|
42
|
-
|
43
|
-
- 2
|
44
|
-
- 6
|
45
|
-
version: "2.6"
|
46
|
-
requirement: *id002
|
47
|
-
prerelease: false
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
48
31
|
name: rspec
|
49
|
-
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
version_requirements: &id003 !ruby/object:Gem::Requirement
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
52
33
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
|
58
|
-
- 0
|
59
|
-
- 6
|
60
|
-
- 0
|
61
|
-
version: 0.6.0
|
62
|
-
requirement: *id003
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.6'
|
38
|
+
type: :development
|
63
39
|
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.6'
|
46
|
+
- !ruby/object:Gem::Dependency
|
64
47
|
name: yard
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.6.0
|
65
54
|
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.6.0
|
66
62
|
description: Rails plugin for sending asynchronous email with ActionMailer and Resque.
|
67
|
-
email:
|
63
|
+
email:
|
68
64
|
- nap@zerosum.org
|
69
65
|
executables: []
|
70
|
-
|
71
66
|
extensions: []
|
72
|
-
|
73
|
-
extra_rdoc_files:
|
67
|
+
extra_rdoc_files:
|
74
68
|
- LICENSE
|
75
69
|
- CHANGELOG.md
|
76
70
|
- README.md
|
77
|
-
files:
|
71
|
+
files:
|
78
72
|
- lib/resque_mailer/version.rb
|
79
73
|
- lib/resque_mailer.rb
|
80
74
|
- README.md
|
@@ -82,36 +76,32 @@ files:
|
|
82
76
|
- CHANGELOG.md
|
83
77
|
homepage: http://github.com/zapnap/resque_mailer
|
84
78
|
licenses: []
|
85
|
-
|
86
79
|
post_install_message:
|
87
80
|
rdoc_options: []
|
88
|
-
|
89
|
-
require_paths:
|
81
|
+
require_paths:
|
90
82
|
- lib
|
91
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
84
|
none: false
|
93
|
-
requirements:
|
94
|
-
- -
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
|
97
|
-
segments:
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
segments:
|
98
90
|
- 0
|
99
|
-
|
100
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
hash: 1935343156117809086
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
93
|
none: false
|
102
|
-
requirements:
|
103
|
-
- -
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
|
106
|
-
segments:
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
segments:
|
107
99
|
- 0
|
108
|
-
|
100
|
+
hash: 1935343156117809086
|
109
101
|
requirements: []
|
110
|
-
|
111
102
|
rubyforge_project:
|
112
|
-
rubygems_version: 1.8.
|
103
|
+
rubygems_version: 1.8.24
|
113
104
|
signing_key:
|
114
105
|
specification_version: 3
|
115
106
|
summary: Rails plugin for sending asynchronous email with ActionMailer and Resque.
|
116
107
|
test_files: []
|
117
|
-
|