2014-05-16 07:58:06 +00:00
|
|
|
module JamRuby
|
|
|
|
|
class EmailBatchPeriodic < EmailBatch
|
|
|
|
|
self.abstract_class = true
|
|
|
|
|
|
2014-05-18 00:12:01 +00:00
|
|
|
def time_since_last_batch_query
|
|
|
|
|
self.class
|
2014-05-17 17:38:22 +00:00
|
|
|
.where(['created_at < ?', self.created_at])
|
2014-07-26 03:58:58 +00:00
|
|
|
.where(:aasm_state => 'delivered')
|
2014-05-17 17:38:22 +00:00
|
|
|
.order('created_at DESC')
|
|
|
|
|
.limit(1)
|
2014-05-18 00:12:01 +00:00
|
|
|
end
|
|
|
|
|
|
2014-05-31 09:36:10 +00:00
|
|
|
def time_since_last_batch(default_days=2)
|
2014-05-18 00:12:01 +00:00
|
|
|
if previous = self.time_since_last_batch_query.first
|
2014-05-17 17:38:22 +00:00
|
|
|
return previous.created_at
|
2014-05-16 07:58:06 +00:00
|
|
|
end
|
2014-05-31 09:36:10 +00:00
|
|
|
Time.now - default_days.days
|
2014-05-16 07:58:06 +00:00
|
|
|
end
|
|
|
|
|
|
2014-05-18 00:12:01 +00:00
|
|
|
def fetch_recipients(since=nil)
|
2014-05-17 17:38:22 +00:00
|
|
|
yield([]) if block_given?
|
2014-05-16 07:58:06 +00:00
|
|
|
end
|
|
|
|
|
|
2014-05-18 00:12:01 +00:00
|
|
|
def self.subject(subtype=nil)
|
2014-05-16 07:58:06 +00:00
|
|
|
''
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.body
|
|
|
|
|
''
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.new(*args)
|
|
|
|
|
oo = super
|
2014-05-18 00:12:01 +00:00
|
|
|
oo.body = ''
|
2014-05-16 07:58:06 +00:00
|
|
|
oo.subject = self.subject
|
|
|
|
|
oo
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def deliver_batch_sets!
|
|
|
|
|
end
|
|
|
|
|
|
2014-05-18 05:24:07 +00:00
|
|
|
def clear_batch_sets!
|
|
|
|
|
self.email_batch_sets.map(&:destroy)
|
|
|
|
|
end
|
|
|
|
|
|
2014-05-16 07:58:06 +00:00
|
|
|
end
|
|
|
|
|
end
|