Improve task for generating invitations
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

Turn the argument into the target number of unused invitations for each
user, thus not generating more invitations for users who already have a
sufficient amount of unused ones.
This commit is contained in:
Basti 2021-11-28 10:40:09 -06:00
parent 8cf631fd94
commit 89913ba60b
Signed by untrusted user: basti
GPG Key ID: 9F88009D31D99C72
1 changed files with 11 additions and 2 deletions

View File

@ -2,12 +2,21 @@ namespace :invitations do
desc "Generate invitations for all users"
task :generate_for_all_users, [:amount_per_user] => :environment do |t, args|
count = 0
User.all.each do |user|
args[:amount_per_user].to_i.times do
amt_to_create = args[:amount_per_user].to_i - user.invitations.unused.count
next unless amt_to_create > 0
amt_created = 0
amt_to_create.times do
user.invitations << Invitation.create(user: user)
count += 1
amt_created += 1
end
puts "Created #{amt_created} new invitations for #{user.address}"
end
puts "Created #{count} new invitations"
puts "---\nCreated #{count} new invitations overall"
end
end