2014-04-04 10:08:00 +00:00
|
|
|
module JamRuby
|
|
|
|
|
class EmailBatchSet < ActiveRecord::Base
|
|
|
|
|
self.table_name = "email_batch_sets"
|
|
|
|
|
|
|
|
|
|
belongs_to :email_batch, :class_name => 'JamRuby::EmailBatch'
|
|
|
|
|
|
2014-04-05 18:52:12 +00:00
|
|
|
def self.deliver_set(batch_id, user_ids)
|
2014-04-04 10:08:00 +00:00
|
|
|
bset = self.new
|
2014-04-05 18:52:12 +00:00
|
|
|
bset.email_batch_id = batch_id
|
2014-04-04 10:08:00 +00:00
|
|
|
bset.user_ids = user_ids.join(',')
|
|
|
|
|
bset.started_at = Time.now
|
2014-04-05 18:52:12 +00:00
|
|
|
bset.batch_count = user_ids.size
|
2014-04-04 10:08:00 +00:00
|
|
|
bset.save!
|
|
|
|
|
|
2014-04-05 18:52:12 +00:00
|
|
|
if 'test' == Rails.env
|
|
|
|
|
BatchMailer.send_batch_email(bset.email_batch_id, user_ids).deliver!
|
2014-04-04 10:23:20 +00:00
|
|
|
else
|
2014-04-05 18:52:12 +00:00
|
|
|
BatchMailer.send_batch_email(bset.email_batch_id, user_ids).deliver
|
2014-04-04 10:23:20 +00:00
|
|
|
end
|
2014-04-04 10:08:00 +00:00
|
|
|
bset
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|