VRFS-1664 some tweaks
This commit is contained in:
parent
7428a2f26b
commit
e330fb96c7
|
|
@ -106,9 +106,6 @@
|
|||
|
||||
sendgrid_recipients([user.email])
|
||||
sendgrid_substitute('@USERID', [user.id])
|
||||
sendgrid_substitute(EmailBatch::VAR_FIRST_NAME, [user.first_name])
|
||||
sendgrid_substitute(EmailBatchNewMusician::VAR_MUSICIAN_COUNT, [new_nearby.count.to_s])
|
||||
|
||||
sendgrid_unique_args :type => "new_musicians"
|
||||
|
||||
mail(:to => user.email, :subject => EmailBatchNewMusician.subject) do |format|
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
module JamRuby
|
||||
class EmailBatchNewMusician < EmailBatchPeriodic
|
||||
|
||||
BATCH_SIZE = 100
|
||||
BATCH_SIZE = 3
|
||||
|
||||
SINCE_WEEKS = 2
|
||||
|
||||
VAR_MUSICIAN_COUNT = "@MUSICIAN_COUNT"
|
||||
VAR_MUSICIAN_TABLE = "@MUSICIAN_TABLE"
|
||||
|
|
@ -10,52 +12,26 @@ module JamRuby
|
|||
"New musicians with good Internet connections to you have joined JamKazam!"
|
||||
end
|
||||
|
||||
def time_since_last_batch
|
||||
if previous = self.class
|
||||
.where(['created_at < ?', self.created_at])
|
||||
.order('created_at DESC')
|
||||
.limit(1)
|
||||
.first
|
||||
return previous.created_at
|
||||
end
|
||||
Time.now - 2.weeks
|
||||
end
|
||||
|
||||
# def self.recipient_count
|
||||
# User.geocoded_users
|
||||
# .email_opt_in
|
||||
# .where(['created_at >= ?', self.time_since_last_batch])
|
||||
# .count
|
||||
# end
|
||||
|
||||
# def self.fetch_recipients
|
||||
# User.geocoded_users
|
||||
# .email_opt_in
|
||||
# .where(['created_at >= ?', self.time_since_last_batch])
|
||||
# .find_in_batches(batch_size: self::BATCH_SIZE) do |users|
|
||||
# new_musicians = users.inject({}) do |hh, uu|
|
||||
# if 0 < (nearby = uu.nearest_musicians).count
|
||||
# hh[uu] = nearby
|
||||
# end
|
||||
# hh
|
||||
# end
|
||||
# yield(new_musicians)
|
||||
# end
|
||||
# end
|
||||
|
||||
def deliver_batch_sets!
|
||||
self.opt_in_count = 0
|
||||
sent = 0
|
||||
def self.fetch_recipients(since=nil)
|
||||
since ||= Time.now - SINCE_WEEKS.weeks
|
||||
User.geocoded_users
|
||||
.email_opt_in
|
||||
.where(['created_at >= ?', self.time_since_last_batch])
|
||||
.find_in_batches(batch_size: EmailBatchNewMusician::BATCH_SIZE) do |users|
|
||||
.where(['created_at < ?', since])
|
||||
.find_in_batches(batch_size: self::BATCH_SIZE) do |users|
|
||||
new_musicians = users.inject({}) do |hh, uu|
|
||||
if 0 < (nearby = uu.nearest_musicians).count
|
||||
hh[uu] = nearby
|
||||
end
|
||||
hh
|
||||
end
|
||||
yield(new_musicians) if block_given?
|
||||
end
|
||||
end
|
||||
|
||||
def deliver_batch_sets!
|
||||
self.opt_in_count = 0
|
||||
sent = 0
|
||||
self.class.fetch_recipients(self.time_since_last_batch(SINCE_WEEKS)) do |new_musicians|
|
||||
self.opt_in_count += new_musicians.count
|
||||
self.email_batch_sets << (bset = EmailBatchSet.load_set(self, new_musicians.keys.map(&:id)))
|
||||
new_musicians.each do |uu, nearby|
|
||||
|
|
@ -65,6 +41,7 @@ module JamRuby
|
|||
end
|
||||
self.sent_count = sent
|
||||
self.save
|
||||
self.did_batch_run!
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,15 +2,19 @@ module JamRuby
|
|||
class EmailBatchPeriodic < EmailBatch
|
||||
self.abstract_class = true
|
||||
|
||||
def self.time_since_last_batch
|
||||
if previous = self.order('created_at DESC').limit(1).first
|
||||
return Time.now - previous.created_at
|
||||
def time_since_last_batch(default_weeks=2)
|
||||
if previous = self.class
|
||||
.where(['created_at < ?', self.created_at])
|
||||
.order('created_at DESC')
|
||||
.limit(1)
|
||||
.first
|
||||
return previous.created_at
|
||||
end
|
||||
nil
|
||||
Time.now - default_weeks.weeks
|
||||
end
|
||||
|
||||
def self.fetch_recipients
|
||||
yield([])
|
||||
def self.fetch_recipients(since=nil)
|
||||
yield([]) if block_given?
|
||||
end
|
||||
|
||||
def self.subject
|
||||
|
|
@ -23,6 +27,7 @@ module JamRuby
|
|||
|
||||
def self.new(*args)
|
||||
oo = super
|
||||
oo.body = nil
|
||||
oo.subject = self.subject
|
||||
oo
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue