mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 05:26:17 +02:00
added validation for single domain contacts
This commit is contained in:
parent
d7df763295
commit
43bd6f2907
3 changed files with 17 additions and 48 deletions
|
@ -66,9 +66,11 @@ module Actions
|
|||
result_validation.present? ? result.success = true : result.success = false
|
||||
end
|
||||
|
||||
contacts.each do |contact|
|
||||
contacts.find_in_batches(batch_size: 500) do |contact_batches|
|
||||
contact_batches.each do |contact|
|
||||
contact.validation_events.create(validation_event_attrs(result))
|
||||
end
|
||||
end
|
||||
rescue ActiveRecord::RecordNotSaved
|
||||
logger.info "Cannot save validation result for #{log_object_id}"
|
||||
true
|
||||
|
|
|
@ -2,9 +2,9 @@ class VerifyEmailsJob < ApplicationJob
|
|||
discard_on StandardError
|
||||
|
||||
def perform(email:, check_level: 'mx')
|
||||
# contact_not_found(contact.id) unless contact
|
||||
contact = Contact.find_by(email: email)
|
||||
|
||||
contact = Contact.find_by_email(email)
|
||||
return Rails.logger.info "No found #{email} contact" if contact.nil?
|
||||
|
||||
return unless filter_check_level(contact)
|
||||
|
||||
|
|
|
@ -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)
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue