refactored

This commit is contained in:
olegphenomenon 2021-11-05 11:42:27 +02:00
parent 64a7e0fb53
commit 59fb12b840
2 changed files with 13 additions and 2 deletions

View file

@ -3,9 +3,11 @@ class VerifyEmailsJob < ApplicationJob
def perform(contact_id:, check_level: 'regex')
contact = Contact.find_by(id: contact_id)
return if check_contact_for_duplicate_mail(contact_id)
contact_not_found(contact_id) unless contact
validate_check_level(check_level)
action = Actions::EmailCheck.new(email: contact.email,
validation_eventable: contact,
check_level: check_level)
@ -17,6 +19,16 @@ class VerifyEmailsJob < ApplicationJob
private
def check_contact_for_duplicate_mail(contact_id)
time = Time.zone.now - ValidationEvent::VALIDATION_PERIOD
contact = Contact.find(contact_id)
contact_ids = Contact.where(email: contact.email).where('created_at > ?', time).pluck(:id)
r = ValidationEvent.where(validation_eventable_id: contact_ids)
r.present?
end
def contact_not_found(contact_id)
raise StandardError, "Contact with contact_id #{contact_id} not found"
end

View file

@ -58,7 +58,6 @@ def prepare_contacts(options)
validation_events_ids = ValidationEvent.where('created_at > ?', time).pluck(:validation_eventable_id)
Contact.where.not(id: validation_events_ids)
# contacts.reject(&:need_to_start_force_delete?) # temporarily commented out code
end
end