37 lines
962 B
Crystal
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
|