mentorenwahl/docker/backend/src/backend/worker/jobs/send_teachers_registration_email_job.cr
Dominic Grimm 5825969be9
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
Documented Worker
2022-02-07 20:58:24 +01:00

37 lines
962 B
Crystal

require "../../db/user"
module Backend
module Worker
module Jobs
# Sends all unregistered teachers a polite registration mail to ask if they may input their data
class SendTeachersRegistrationEmailJob < Mosquito::QueuedJob
# :ditto:
def perform : Nil
users = Db::User.where(role: Db::UserRole::Teacher.to_s, teacher_id: nil)
count = users.count.run.as(Int64).to_i
channel = Channel(Nil).new(count)
users.each do |user|
spawn do
unless Db::UserRole.parse(user.role).teacher?
fail
end
log "Sending teacher registration email to #{user.email} (#{user.id})"
Mailers::TeacherRegistrationMailer.new(user).deliver
channel.send(nil)
end
end
count.times do
channel.receive
end
Fiber.yield
end
end
end
end
end