-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add in some optional parameters (#1979)
- Loading branch information
Cory McDonald
authored
Jun 19, 2019
1 parent
48b5494
commit fdce479
Showing
1 changed file
with
16 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |