mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 09:21:43 +02:00
Merge pull request #2212 from internetee/added_notifications_for_acc_center
added mail contronller and job for notificate registrars and admins about accreditation expire date
This commit is contained in:
commit
4ccbbd2292
10 changed files with 167 additions and 4 deletions
36
app/jobs/notify_accreditation_admins_and_registrars_job.rb
Normal file
36
app/jobs/notify_accreditation_admins_and_registrars_job.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
class NotifyAccreditationAdminsAndRegistrarsJob < ApplicationJob
|
||||
MONTH_BEFORE = 5.minutes.freeze
|
||||
|
||||
def perform
|
||||
notify_month_before
|
||||
notify_date_is_expired
|
||||
end
|
||||
|
||||
def notify_month_before
|
||||
prepare_data_month_before.each do |user|
|
||||
next if user.registrar.email.nil?
|
||||
|
||||
AccreditationCenterMailer.test_results_will_expired_in_one_month(user.registrar.email).deliver_now
|
||||
end
|
||||
end
|
||||
|
||||
def notify_date_is_expired
|
||||
prepare_data_expired_data.each do |user|
|
||||
next if user.registrar.email.nil?
|
||||
|
||||
AccreditationCenterMailer.test_results_are_expired(user.registrar.email).deliver_now
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def prepare_data_month_before
|
||||
ApiUser.where('accreditation_expire_date > ? AND accreditation_expire_date < ?',
|
||||
Time.zone.now.beginning_of_day + MONTH_BEFORE,
|
||||
Time.zone.now.end_of_day + MONTH_BEFORE).includes(:registrar)
|
||||
end
|
||||
|
||||
def prepare_data_expired_data
|
||||
ApiUser.where('accreditation_expire_date < ?', Time.zone.now.beginning_of_day).includes(:registrar)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue