Created
November 25, 2013 07:54
-
-
Save goldnuggets24/7637864 to your computer and use it in GitHub Desktop.
referred_email.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReferredEmail < Struct.new(:orig_email) | |
def perform | |
# Send to All Card Referrals except for Signups | |
@deals_count = Deal.all.select{|a|a.vote_score > -3 && a.organization.searchable == true}.count | |
referrals = (CardReferral.all.map(&:email).map(&:downcase) - CardSignup.all.map(&:email).map(&:downcase)).uniq | |
email_referrals = orig_email.card_referrals.map(&:email) | |
referrals = referrals - email_referrals | |
referrals.each do |cf| | |
begin | |
@cf = CardReferral.find_by_email(cf) | |
unless @cf.emails.include?(orig_email) | |
Notifier.referred_magic_email(User.find(@cf.user_id), @cf.email, @cf.name, orig_email.subject, @cf.message, orig_email, @deals_count).deliver | |
@cf.emails << Email.find(orig_email) | |
end | |
rescue | |
# Do nothing - let's just not let it restart the job for now | |
end | |
end | |
return true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment