added validation for single domain contacts

This commit is contained in:
olegphenomenon 2022-04-25 14:37:46 +03:00
parent d7df763295
commit 43bd6f2907
3 changed files with 17 additions and 48 deletions

View file

@ -18,29 +18,13 @@ namespace :verify_email do
options = RakeOptionParserBoilerplate.process_args(options: options,
banner: banner,
hash: opts_hash)
# batch_contacts = prepare_contacts(options)
# logger.info 'No contacts to check email selected' and next if batch_contacts.blank?
# batch_contacts.find_in_batches(batch_size: 10_000) do |contacts|
# contacts.each do |contact|
# VerifyEmailsJob.set(wait_until: spam_protect_timeout(options)).perform_later(
# contact: contact,
# check_level: check_level(options)
# ) if filter_check_level(contact)
# end
# end
email_contacts = prepare_contacts(options)
email_contacts.each do |email|
VerifyEmailsJob.set(wait_until: spam_protect_timeout(options)).perform_later(
# contact: contact,
email: email,
check_level: check_level(options)
)
# if filter_check_level(contact)
VerifyEmailsJob.set(wait_until: spam_protect_timeout(options)).perform_later(
email: email,
check_level: check_level(options)
)
end
end
end
@ -63,40 +47,23 @@ end
def prepare_contacts(options)
if options[:domain_name].present?
Rails.logger.info 'NEED TO TODO'
# contacts_by_domain(options[:domain_name])
contacts_by_domain(options[:domain_name])
else
time = Time.zone.now - ValidationEvent::VALIDATION_PERIOD
validation_events_ids = ValidationEvent.where('created_at > ?', time).distinct.pluck(:validation_eventable_id)
contacts_ids = Contact.where.not(id: validation_events_ids).pluck(:id)
Contact.where(id: contacts_ids + failed_contacts).group_by(&:email).keys
# Contact.all.group_by(&:email).keys
contacts_emails = Contact.where.not(id: validation_events_ids).pluck(:email)
# Contact.where(id: contacts_ids + failed_contacts).pluck(:email).uniq
(contacts_emails + failed_email_contacts).uniq
end
end
def filter_check_level(contact)
return true unless contact.validation_events.exists?
data = contact.validation_events.order(created_at: :asc).last
return true if data.successful? && data.created_at < (Time.zone.now - ValidationEvent::VALIDATION_PERIOD)
if data.failed?
return false if data.event_data['check_level'] == 'regex'
return true
end
false
end
def failed_contacts
def failed_email_contacts
failed_contacts = []
failed_validations_ids = ValidationEvent.failed.distinct.pluck(:validation_eventable_id)
contacts = Contact.where(id: failed_validations_ids).includes(:validation_events)
contacts.find_each(batch_size: 10_000) do |contact|
failed_contacts << contact.id if filter_check_level(contact)
failed_contacts << contact.email
end
failed_contacts.uniq
@ -106,7 +73,7 @@ def contacts_by_domain(domain_name)
domain = ::Domain.find_by(name: domain_name)
return unless domain
domain.contacts
domain.contacts.pluck(:email).uniq
end
def opts_hash