15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'app/models/campagne/sender_job.rb', line 15
def self.perform(campaign_id)
ActiveSupport::BufferedLogger.new(Rails.root.join('log/resque.log')).info([Time.now.iso8601, $$, "I", "---PERFORM---", campaign_id].join("\t"))
campaign = Campaign.find(campaign_id)
contacts = campaign.lists.map(&:contacts).flatten
contacts = contacts.sort_by {rand} contacts.each do |contact|
next if campaign.deliveries.where(:contact_id => contact.id).first
token = generate_token
Sender.deliver_email(contact.email, campaign.subject, campaign.formated_body(token), token)
campaign.deliveries.create(:contact_id => contact.id, :email => contact.email, :token => token)
end
end
|