WIP
This commit is contained in:
parent
b9eff8dac0
commit
73a87a6d45
|
|
@ -401,18 +401,18 @@ module JamRuby
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_musicians_match(user, musicians_data)
|
def new_musicians_match(user, musicians_data, receipents)
|
||||||
@user, @musicians_data = user, musicians_data
|
@user, @musicians_data = user, musicians_data
|
||||||
@instrument_proficiencies = {
|
@instrument_proficiencies = {
|
||||||
'1': 'Beginner',
|
'1': 'Beginner',
|
||||||
'2': 'Intermediate',
|
'2': 'Intermediate',
|
||||||
'3': 'Expert'
|
'3': 'Expert'
|
||||||
}
|
}
|
||||||
sendgrid_recipients([user.email])
|
sendgrid_recipients(receipents)
|
||||||
sendgrid_substitute('@USERID', [user.id])
|
sendgrid_substitute('@USERID', [user.id])
|
||||||
sendgrid_unique_args :type => "new_musicians_match"
|
sendgrid_unique_args :type => "new_musicians_match"
|
||||||
|
|
||||||
mail(:to => user.email, :subject => EmailNewMusicianMatch.subject) do |format|
|
mail(:to => receipents, :subject => EmailNewMusicianMatch.subject) do |format|
|
||||||
format.text
|
format.text
|
||||||
format.html { render layout: "user_mailer_beta" }
|
format.html { render layout: "user_mailer_beta" }
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
module JamRuby
|
module JamRuby
|
||||||
class EmailNewMusicianMatch
|
class EmailNewMusicianMatch
|
||||||
|
|
||||||
PER_PAGE = 150
|
PER_PAGE = 10
|
||||||
LIMIT = 20
|
LIMIT = 300
|
||||||
JOINED_WITHIN_DAYS = 7
|
JOINED_WITHIN_DAYS = 7
|
||||||
ACTIVE_WITHIN_DAYS = 30
|
ACTIVE_WITHIN_DAYS = 30
|
||||||
|
|
||||||
|
|
@ -27,72 +27,77 @@ module JamRuby
|
||||||
limit: PER_PAGE
|
limit: PER_PAGE
|
||||||
}
|
}
|
||||||
|
|
||||||
email_sending = UserMatchEmailSending.most_recent
|
#email_sending = UserMatchEmailSending.most_recent
|
||||||
if email_sending.nil? || email_sending.completed?
|
#if email_sending.nil? || email_sending.completed?
|
||||||
email_sending = UserMatchEmailSending.create
|
# email_sending = UserMatchEmailSending.create
|
||||||
end
|
#end
|
||||||
|
|
||||||
|
# support easy overrides for iterative testing
|
||||||
|
limit = ENV["FORCED_BATCH_LIMIT"] || LIMIT
|
||||||
|
limit = limit.to_i
|
||||||
|
|
||||||
|
send_to_jk_employees = ENV["SEND_TO_JK_EMPLOYEES"] == '1' || APP_CONFIG.send_user_match_mail_only_to_jamkazam_team
|
||||||
|
|
||||||
|
monitoring_email_specified = !APP_CONFIG.user_match_monitoring_email.blank?
|
||||||
|
|
||||||
|
puts "EmailNewMusicianMatch: limit: #{limit}, send_to_jk_employees: #{send_to_jk_employees}"
|
||||||
begin
|
begin
|
||||||
recipients = User.where("users.subscribe_email = ? AND
|
recipients = User.where("users.subscribe_email = ? AND
|
||||||
users.subscribe_email_for_user_match = ?
|
users.subscribe_email_for_user_match = ?
|
||||||
AND NOT COALESCE(users.user_match_email_sent_at, ?) > ?",
|
AND NOT COALESCE(users.user_match_email_sent_at, ?) > ?",
|
||||||
true, true, 7.days.ago, 6.days.ago).where.not(id: email_sending.sent_user_ids).order("
|
true, true, 7.days.ago, 6.days.ago)
|
||||||
CASE WHEN users.email IN ('#{PRIORITY_RECIPIENTS.map {|str| "\"#{str}\""}.join(',')}')
|
.where.not(id: email_sending.sent_user_ids)
|
||||||
THEN 0 ELSE 1 END, last_active_at DESC").select("users.*,
|
.order("last_active_at DESC")
|
||||||
GREATEST(updated_at, last_jam_updated_at) AS last_active_at").limit(LIMIT)
|
.select("users.*, GREATEST(updated_at, last_jam_updated_at) AS last_active_at")
|
||||||
|
.limit(LIMIT)
|
||||||
# If the flag is set to send user match email only to jamkazam team
|
|
||||||
if Rails.application.config.send_user_match_mail_only_to_jamkazam_team
|
|
||||||
recipients = recipients.where(email: PRIORITY_RECIPIENTS)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
if monitoring_email_specified
|
||||||
AdminMailer.ugly({to: APP_CONFIG.user_match_monitoring_email,
|
AdminMailer.ugly({to: APP_CONFIG.user_match_monitoring_email,
|
||||||
subject:"Weekly user match email sending job started.",
|
subject:"Weekly user match email sending job started.",
|
||||||
body: "#{email_sending.sent_user_ids.any?? "This job is resuming. It was originally started at #{email_sending.created_at} and has been sent to #{email_sending.sent_user_ids.size} user(s) so far." : "This job was started at #{email_sending.created_at}" }. It will send to total of #{ recipients.size } users."}).deliver_now
|
body: "#{email_sending.sent_user_ids.any?? "This job is resuming. It was originally started at #{email_sending.created_at} and has been sent to #{email_sending.sent_user_ids.size} user(s) so far." : "This job was started at #{email_sending.created_at}" }. It will send to total of #{ recipients.size } users."}).deliver_now
|
||||||
|
end
|
||||||
|
|
||||||
recipients.find_each do |user|
|
recipients.find_each do |user|
|
||||||
|
|
||||||
ip_address = user.last_jam_addr.blank?? '127.0.0.1' : IPAddr.new(user.last_jam_addr, Socket::AF_INET).to_s
|
ip_address = user.last_jam_addr.blank?? '127.0.0.1' : IPAddr.new(user.last_jam_addr, Socket::AF_INET).to_s
|
||||||
matched_musician_data = []
|
matched_musician_data = []
|
||||||
nextOffset = 0
|
|
||||||
|
|
||||||
while !nextOffset.nil? && nextOffset >= 0 do
|
|
||||||
|
|
||||||
params.merge!({ offset: nextOffset })
|
params.merge!({ offset: nextOffset })
|
||||||
|
|
||||||
results, latency_data, nextOffset = JamRuby::MusicianFilter.filter(user, ip_address, params)
|
results, latency_data, nextOffset = JamRuby::MusicianFilter.filter(user, ip_address, params)
|
||||||
|
|
||||||
matched_musician_data << [{ musicians: results, latencies: latency_data }] if results && results.size > 0
|
matched_musician_data << [{ musicians: results, latencies: latency_data }] if results && results.size > 0
|
||||||
end
|
|
||||||
|
|
||||||
|
send_to_receipents = send_to_jk_employees ? PRIORITY_RECIPIENTS : [user.email]
|
||||||
|
user.update_column(:user_match_email_sent_at, Time.now, :user_match_num_matched, matched_musician_data.size)
|
||||||
|
|
||||||
if matched_musician_data.size > 0
|
if matched_musician_data.size > 0
|
||||||
|
UserMailer.new_musicians_match(user, matched_musician_data, send_to_receipents).deliver_now
|
||||||
UserMailer.new_musicians_match(user, matched_musician_data).deliver_now
|
#email_sending.sent_user_ids.push(user.id)
|
||||||
|
#email_sending.save!
|
||||||
user.update_column(:user_match_email_sent_at, Time.now)
|
|
||||||
email_sending.sent_user_ids.push(user.id)
|
|
||||||
email_sending.save!
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
email_sending.total_recipients = email_sending.sent_user_ids.size
|
#email_sending.total_recipients = email_sending.sent_user_ids.size
|
||||||
email_sending.completed_at = Time.now
|
#email_sending.completed_at = Time.now
|
||||||
email_sending.save!
|
#email_sending.save!
|
||||||
|
|
||||||
|
if monitoring_email_specified
|
||||||
AdminMailer.ugly({
|
AdminMailer.ugly({
|
||||||
to: APP_CONFIG.user_match_monitoring_email,
|
to: APP_CONFIG.user_match_monitoring_email,
|
||||||
subject:"Weekly user match email sending completed.",
|
subject:"Weekly user match email sending completed.",
|
||||||
body: "Weekly email sending job was completed at #{Time.now}. It was sent to #{email_sending.sent_user_ids.size} user(s)."
|
body: "Weekly email sending job was completed at #{Time.now}. It was sent to #{email_sending.sent_user_ids.size} user(s)."
|
||||||
}).deliver_now
|
}).deliver_now
|
||||||
|
end
|
||||||
|
|
||||||
rescue => exception
|
rescue => exception
|
||||||
begin
|
begin
|
||||||
fail_count = email_sending.fail_count
|
#fail_count = email_sending.fail_count
|
||||||
email_sending.update_attributes(fail_count: fail_count + 1, exception_detail: exception.message)
|
#email_sending.update_attributes(fail_count: fail_count + 1, exception_detail: exception.message)
|
||||||
|
|
||||||
|
if monitoring_email_specified
|
||||||
AdminMailer.ugly({to: APP_CONFIG.user_match_monitoring_email,
|
AdminMailer.ugly({to: APP_CONFIG.user_match_monitoring_email,
|
||||||
subject:"Error occured when sending weekly user match email.",
|
subject:"Error occured when sending weekly user match email.",
|
||||||
body: "An error was encountered at #{Time.now} while sending weekly user match email - #{exception.message}."}).deliver_now
|
body: "An error was encountered at #{Time.now} while sending weekly user match email - #{exception.message}."}).deliver_now
|
||||||
|
end
|
||||||
rescue
|
rescue
|
||||||
Bugsnag.notify(exception)
|
Bugsnag.notify(exception)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue