mirror of
https://github.com/internetee/registry.git
synced 2025-08-11 12:09:34 +02:00
refactoring-job-validation-email
This commit is contained in:
parent
219b48d9e3
commit
d7df763295
3 changed files with 56 additions and 26 deletions
|
@ -50,6 +50,8 @@ module Actions
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_result(result)
|
def save_result(result)
|
||||||
|
contacts = Contact.where(email: email)
|
||||||
|
|
||||||
if !result.success && @check_level == "mx"
|
if !result.success && @check_level == "mx"
|
||||||
result_validation = Actions::AAndAaaaEmailValidation.call(email: @email, value: 'A')
|
result_validation = Actions::AAndAaaaEmailValidation.call(email: @email, value: 'A')
|
||||||
output_a_and_aaaa_validation_results(email: @email,
|
output_a_and_aaaa_validation_results(email: @email,
|
||||||
|
@ -62,9 +64,10 @@ module Actions
|
||||||
type: 'AAAA')
|
type: 'AAAA')
|
||||||
|
|
||||||
result_validation.present? ? result.success = true : result.success = false
|
result_validation.present? ? result.success = true : result.success = false
|
||||||
validation_eventable.validation_events.create(validation_event_attrs(result))
|
end
|
||||||
else
|
|
||||||
validation_eventable.validation_events.create(validation_event_attrs(result))
|
contacts.each do |contact|
|
||||||
|
contact.validation_events.create(validation_event_attrs(result))
|
||||||
end
|
end
|
||||||
rescue ActiveRecord::RecordNotSaved
|
rescue ActiveRecord::RecordNotSaved
|
||||||
logger.info "Cannot save validation result for #{log_object_id}"
|
logger.info "Cannot save validation result for #{log_object_id}"
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
class VerifyEmailsJob < ApplicationJob
|
class VerifyEmailsJob < ApplicationJob
|
||||||
discard_on StandardError
|
discard_on StandardError
|
||||||
|
|
||||||
def perform(contact:, check_level: 'mx')
|
def perform(email:, check_level: 'mx')
|
||||||
contact_not_found(contact.id) unless contact
|
# contact_not_found(contact.id) unless contact
|
||||||
|
|
||||||
|
contact = Contact.find_by_email(email)
|
||||||
|
|
||||||
|
return unless filter_check_level(contact)
|
||||||
|
|
||||||
validate_check_level(check_level)
|
validate_check_level(check_level)
|
||||||
action = Actions::EmailCheck.new(email: contact.email,
|
action = Actions::EmailCheck.new(email: contact.email,
|
||||||
validation_eventable: contact,
|
validation_eventable: contact,
|
||||||
|
@ -32,4 +37,24 @@ class VerifyEmailsJob < ApplicationJob
|
||||||
def valid_check_levels
|
def valid_check_levels
|
||||||
ValidationEvent::VALID_CHECK_LEVELS
|
ValidationEvent::VALID_CHECK_LEVELS
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_validation_results(contact)
|
||||||
|
ValidationEvent.where(created_at: Time.zone.now.beginning_of_day..Time.zone.now.end_of_day)
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,17 +19,28 @@ namespace :verify_email do
|
||||||
banner: banner,
|
banner: banner,
|
||||||
hash: opts_hash)
|
hash: opts_hash)
|
||||||
|
|
||||||
batch_contacts = prepare_contacts(options)
|
# batch_contacts = prepare_contacts(options)
|
||||||
logger.info 'No contacts to check email selected' and next if batch_contacts.blank?
|
# 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|
|
# batch_contacts.find_in_batches(batch_size: 10_000) do |contacts|
|
||||||
contacts.each do |contact|
|
# 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(
|
VerifyEmailsJob.set(wait_until: spam_protect_timeout(options)).perform_later(
|
||||||
contact: contact,
|
# contact: contact,
|
||||||
|
email: email,
|
||||||
check_level: check_level(options)
|
check_level: check_level(options)
|
||||||
) if filter_check_level(contact)
|
)
|
||||||
end
|
# if filter_check_level(contact)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -51,13 +62,16 @@ end
|
||||||
|
|
||||||
def prepare_contacts(options)
|
def prepare_contacts(options)
|
||||||
if options[:domain_name].present?
|
if options[:domain_name].present?
|
||||||
contacts_by_domain(options[:domain_name])
|
Rails.logger.info 'NEED TO TODO'
|
||||||
|
# contacts_by_domain(options[:domain_name])
|
||||||
else
|
else
|
||||||
time = Time.zone.now - ValidationEvent::VALIDATION_PERIOD
|
time = Time.zone.now - ValidationEvent::VALIDATION_PERIOD
|
||||||
validation_events_ids = ValidationEvent.where('created_at > ?', time).distinct.pluck(:validation_eventable_id)
|
validation_events_ids = ValidationEvent.where('created_at > ?', time).distinct.pluck(:validation_eventable_id)
|
||||||
|
|
||||||
contacts_ids = Contact.where.not(id: validation_events_ids).pluck(:id)
|
contacts_ids = Contact.where.not(id: validation_events_ids).pluck(:id)
|
||||||
Contact.where(id: contacts_ids + failed_contacts)
|
Contact.where(id: contacts_ids + failed_contacts).group_by(&:email).keys
|
||||||
|
|
||||||
|
# Contact.all.group_by(&:email).keys
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -71,10 +85,6 @@ def filter_check_level(contact)
|
||||||
if data.failed?
|
if data.failed?
|
||||||
return false if data.event_data['check_level'] == 'regex'
|
return false if data.event_data['check_level'] == 'regex'
|
||||||
|
|
||||||
# return false if data.event_data['check_level'] == 'smtp'
|
|
||||||
#
|
|
||||||
# return false if check_mx_contact_validation(contact)
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -92,14 +102,6 @@ def failed_contacts
|
||||||
failed_contacts.uniq
|
failed_contacts.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
# def check_mx_contact_validation(contact)
|
|
||||||
# data = contact.validation_events.mx.order(created_at: :asc).last(ValidationEvent::MX_CHECK)
|
|
||||||
#
|
|
||||||
# return false if data.size < ValidationEvent::MX_CHECK
|
|
||||||
#
|
|
||||||
# data.all? { |d| d.failed? }
|
|
||||||
# end
|
|
||||||
|
|
||||||
def contacts_by_domain(domain_name)
|
def contacts_by_domain(domain_name)
|
||||||
domain = ::Domain.find_by(name: domain_name)
|
domain = ::Domain.find_by(name: domain_name)
|
||||||
return unless domain
|
return unless domain
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue