Skip to content

Commit d7e20f9

Browse files
committed
Merge pull request coderwall#196 from just3ws/master
Added more logging and outer guard to the emails sender because some users have invalid emails
2 parents aca80aa + 92bc485 commit d7e20f9

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

app/mailers/protip_mailer.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class ProtipMailer < ActionMailer::Base
1616
endorsements: 'endorsements',
1717
protips_count: 'protips'
1818
}
19-
ACTIVITY_SUBJECT_PREFIX = '[Coderwall]'
2019
CAMPAIGN_ID = 'protip_mailer-popular_protips'
2120

2221
#################################################################################

app/workers/protip_mailer_popular_protips_worker.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@ def perform(from, to)
66
protips = ProtipMailer::Queries.popular_protips(from, to)
77

88
User.find_each(batch_size: 100) do |user|
9-
ProtipMailer.popular_protips(user, protips, from, to).deliver
9+
begin
10+
if REDIS.sismember(ProtipMailer::CAMPAIGN_ID, user.id.to_s)
11+
Rails.logger.warn("Already sent email to #{user.id} please check Redis SET #{ProtipMailer::CAMPAIGN_ID}.")
12+
else
13+
Rails.logger.warn("Sending email to #{user.id}.")
14+
ProtipMailer.popular_protips(user, protips, from, to).deliver
15+
end
16+
rescue => ex
17+
Rails.logger.error("[ProtipMailer.popular_protips] Unable to send email due to '#{ex}' >>\n#{ex.backtrace.join("\n ")}")
18+
Rails.logger.ap([from, to, user, protips], :error)
19+
end
1020
end
1121
end
1222
end

0 commit comments

Comments
 (0)