From fdce4797bd68500f28a06c1c0d12e777d69a2b4b Mon Sep 17 00:00:00 2001 From: Cory McDonald Date: Wed, 19 Jun 2019 14:08:20 -0500 Subject: [PATCH] Add in some optional parameters (#1979) --- lib/tasks/email_tos_update.rake | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/tasks/email_tos_update.rake b/lib/tasks/email_tos_update.rake index 63b192c858..89a675ce8c 100644 --- a/lib/tasks/email_tos_update.rake +++ b/lib/tasks/email_tos_update.rake @@ -1,19 +1,27 @@ namespace :email do - task :tos_update => :environment do - puts "Emailing #{Publisher.count} users" + task :tos_update, [:id ] => :environment do |t, args| - Publisher.order(:id).find_each.with_index do |user, index| + publisher = Publisher + if args[:id].present? + publisher = publisher.where("id >= ?", args[:id]) + end + + puts "Emailing #{publisher.count} users" + publisher.order(id: :desc).find_each.with_index do |user, index| begin PublisherMailer.update_to_tos(user).deliver_now print '.' if index % 1000 == 0 - rescue - # Let's rescue all exceptions - print "X" - Rails.logger.info "[#{Time.now.iso8601}] Could not send terms and conditions for [#{user.id}]" + rescue => ex + puts + puts "Rescued from exception: #{ex.message}" + puts "Could not send email to #{user.id} - Restart the job by running the following" + puts + puts " rake email:tos_update[\"#{user.id}\"]" + break end end puts - puts "✨ Done" + puts "Done" end end