sidekiq_mailer 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +34 -3
- data/lib/sidekiq_mailer.rb +1 -1
- data/lib/sidekiq_mailer/version.rb +1 -1
- data/test/sidekiq_mailer_test.rb +6 -0
- metadata +1 -1
data/README.md
CHANGED
@@ -1,6 +1,34 @@
|
|
1
1
|
# Sidekiq::Mailer
|
2
2
|
|
3
|
-
|
3
|
+
Sidekiq::Mailer adds to your ActionMailer classes the ability to send mails asyncronously.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
If you want to make a specific mailer to work asyncronously just include Sikekiq::Mailer module:
|
8
|
+
|
9
|
+
class MyMailer < ActionMailer::Base
|
10
|
+
include Sidekiq::Mailer
|
11
|
+
|
12
|
+
def welcome(to)
|
13
|
+
...
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Now every deliver you make with MyMailer will be asyncronous.
|
18
|
+
|
19
|
+
# Queues the mail to be sent asyncronously by sidekiq
|
20
|
+
MyMailer.welcome('your@email.com').deliver
|
21
|
+
|
22
|
+
The default queue used by Sidekiq::Mailer is 'mailer'. So, in order to send mails with sidekiq you need to start a worker using:
|
23
|
+
|
24
|
+
sidekiq -q mailer
|
25
|
+
|
26
|
+
If you want to skip sidekiq you should use the 'deliver!' method:
|
27
|
+
|
28
|
+
# Mail will skip sidekiq and will be sent syncronously
|
29
|
+
MyMailer.welcome('your@email.com').deliver!
|
30
|
+
|
31
|
+
By default Sidekiq::Mailer will retry to send an email if it failed. But you can [override sidekiq options](https://github.com/andersondias/sidekiq_mailer/wiki/Overriding-sidekiq-options) in your mailer.
|
4
32
|
|
5
33
|
## Installation
|
6
34
|
|
@@ -16,9 +44,12 @@ Or install it yourself as:
|
|
16
44
|
|
17
45
|
$ gem install sidekiq_mailer
|
18
46
|
|
19
|
-
##
|
47
|
+
## Testing
|
48
|
+
|
49
|
+
Delayed e-mails is an awesome thing in production environments, but for e-mail specs/tests in testing environments it can be a mess causing specs/tests to fail because the e-mail haven't been sent directly. Therefore you can configure what environments that should be excluded like so:
|
20
50
|
|
21
|
-
|
51
|
+
# config/initializers/sidekiq_mailer.rb
|
52
|
+
Sidekiq::Mailer.excluded_environments = [:test, :cucumber]
|
22
53
|
|
23
54
|
## Contributing
|
24
55
|
|
data/lib/sidekiq_mailer.rb
CHANGED
@@ -35,7 +35,7 @@ module Sidekiq
|
|
35
35
|
self.sidekiq_options_hash = get_sidekiq_options.merge(stringify_keys(opts || {}))
|
36
36
|
end
|
37
37
|
|
38
|
-
DEFAULT_OPTIONS = { 'retry' =>
|
38
|
+
DEFAULT_OPTIONS = { 'retry' => true, 'queue' => 'mailer' }
|
39
39
|
|
40
40
|
def get_sidekiq_options # :nodoc:
|
41
41
|
self.sidekiq_options_hash ||= DEFAULT_OPTIONS
|
data/test/sidekiq_mailer_test.rb
CHANGED
@@ -45,6 +45,12 @@ class SidekiqMailerTest < Test::Unit::TestCase
|
|
45
45
|
assert_equal 'mailer', Sidekiq::Mailer::Worker.jobs.first['queue']
|
46
46
|
end
|
47
47
|
|
48
|
+
def test_default_sidekiq_options
|
49
|
+
BasicMailer.welcome('test@test.com').deliver
|
50
|
+
assert_equal 'mailer', Sidekiq::Mailer::Worker.jobs.first['queue']
|
51
|
+
assert_equal true, Sidekiq::Mailer::Worker.jobs.first['retry']
|
52
|
+
end
|
53
|
+
|
48
54
|
def test_enables_sidekiq_options_overriding
|
49
55
|
MailerInAnotherQueue.bye('test@test.com').deliver
|
50
56
|
assert_equal 'priority', Sidekiq::Mailer::Worker.jobs.first['queue']
|