Skip to content

Commit

Permalink
Add in some optional parameters (#1979)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cory McDonald authored Jun 19, 2019
1 parent 48b5494 commit fdce479
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions lib/tasks/email_tos_update.rake
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fdce479

Please sign in to comment.