diff --git a/app/mailers/protip_mailer.rb b/app/mailers/protip_mailer.rb index a10bf4a3..b6abf4fb 100644 --- a/app/mailers/protip_mailer.rb +++ b/app/mailers/protip_mailer.rb @@ -16,7 +16,6 @@ class ProtipMailer < ActionMailer::Base endorsements: 'endorsements', protips_count: 'protips' } - ACTIVITY_SUBJECT_PREFIX = '[Coderwall]' CAMPAIGN_ID = 'protip_mailer-popular_protips' ################################################################################# diff --git a/app/workers/protip_mailer_popular_protips_worker.rb b/app/workers/protip_mailer_popular_protips_worker.rb index cf9e520d..1795acf2 100644 --- a/app/workers/protip_mailer_popular_protips_worker.rb +++ b/app/workers/protip_mailer_popular_protips_worker.rb @@ -6,7 +6,17 @@ def perform(from, to) protips = ProtipMailer::Queries.popular_protips(from, to) User.find_each(batch_size: 100) do |user| - ProtipMailer.popular_protips(user, protips, from, to).deliver + begin + if REDIS.sismember(ProtipMailer::CAMPAIGN_ID, user.id.to_s) + Rails.logger.warn("Already sent email to #{user.id} please check Redis SET #{ProtipMailer::CAMPAIGN_ID}.") + else + Rails.logger.warn("Sending email to #{user.id}.") + ProtipMailer.popular_protips(user, protips, from, to).deliver + end + rescue => ex + Rails.logger.error("[ProtipMailer.popular_protips] Unable to send email due to '#{ex}' >>\n#{ex.backtrace.join("\n ")}") + Rails.logger.ap([from, to, user, protips], :error) + end end end end