queued_mail 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +9 -1
- data/lib/queued_mail/engine.rb +2 -0
- data/lib/queued_mail/job.rb +21 -2
- data/lib/queued_mail/version.rb +1 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -30,7 +30,7 @@ ActionMailer::Base#deliverでを実際のメール送信ではなくジョブキ
|
|
30
30
|
|
31
31
|
Gemfile
|
32
32
|
|
33
|
-
gem 'queued_mail', '~> 0.2.
|
33
|
+
gem 'queued_mail', '~> 0.2.6'
|
34
34
|
|
35
35
|
bundle install
|
36
36
|
|
@@ -93,6 +93,14 @@ Gemfile
|
|
93
93
|
config.mail_queue_name = '1で作成したキューの名前'
|
94
94
|
|
95
95
|
|
96
|
+
== メール取りだしのリトライ設定
|
97
|
+
|
98
|
+
DBのコミット前にキューを取得してしまった場合など、ジョブ実行の段階でメッセージを取得できない可能性に対処するため、指定回数までメールの取得を試みるようにしました。
|
99
|
+
|
100
|
+
config.mail_queue_retry_limit = 3 # 3回まで再試行する(最初の1回+再試行3回)
|
101
|
+
config.mail_queue_retry_interval = 5 # 5秒後に再試行
|
102
|
+
|
103
|
+
|
96
104
|
== TODO
|
97
105
|
|
98
106
|
- Workerとかめんどくさい人用 cronで叩けるコントローラ
|
data/lib/queued_mail/engine.rb
CHANGED
@@ -11,5 +11,7 @@ module QueuedMail
|
|
11
11
|
config.mail_queue_name = :mail_queue
|
12
12
|
config.mail_queue_outbound_delivery_method = :sendmail
|
13
13
|
config.mail_queue_outbound_mailer = 'QueuedMail::Mailer'
|
14
|
+
config.mail_queue_retry_interval = 5
|
15
|
+
config.mail_queue_retry_limit = 3
|
14
16
|
end
|
15
17
|
end
|
data/lib/queued_mail/job.rb
CHANGED
@@ -3,17 +3,36 @@ module QueuedMail
|
|
3
3
|
@queue = Rails.application.config.mail_queue_name.to_sym
|
4
4
|
|
5
5
|
def self.perform(args)
|
6
|
-
|
6
|
+
retried = 0
|
7
|
+
begin
|
8
|
+
message = QueuedMail::Message.lock.find(args["message_id"].to_i)
|
9
|
+
rescue ActiveRecord::RecordNotFound => e
|
10
|
+
if retried < retry_limit
|
11
|
+
retried += 1
|
12
|
+
sleep retry_interval
|
13
|
+
retry
|
14
|
+
else
|
15
|
+
raise e
|
16
|
+
end
|
17
|
+
end
|
7
18
|
|
8
|
-
message.lock!
|
9
19
|
mailer.original_email(message).deliver
|
10
20
|
message.destroy
|
11
21
|
rescue ActiveRecord::RecordNotFound => e
|
22
|
+
Rails.logger.error e.message
|
12
23
|
# nothing raises
|
13
24
|
end
|
14
25
|
|
15
26
|
def self.mailer
|
16
27
|
@mailer ||= instance_eval(Rails.application.config.mail_queue_outbound_mailer)
|
17
28
|
end
|
29
|
+
|
30
|
+
def self.retry_limit
|
31
|
+
Rails.application.config.mail_queue_retry_limit
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.retry_interval
|
35
|
+
Rails.application.config.mail_queue_retry_interval
|
36
|
+
end
|
18
37
|
end
|
19
38
|
end
|
data/lib/queued_mail/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: queued_mail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
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-11-
|
12
|
+
date: 2012-11-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|