53 lines
1.7 KiB
Crystal
53 lines
1.7 KiB
Crystal
# Mentorenwahl: A fullstack application for assigning mentors to students based on their whishes.
|
|
# Copyright (C) 2022 Dominic Grimm
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
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
|