updated: also validated contacts which was failed without any time limits

This commit is contained in:
olegphenomenon 2021-11-11 14:24:02 +02:00
parent 8b9fbafeb4
commit 5ea5dd7197
4 changed files with 44 additions and 21 deletions

View file

@ -25,7 +25,6 @@ class VerifyEmailsJob < ApplicationJob
contact_ids = Contact.where(email: contact.email).where('created_at > ?', time).pluck(:id) contact_ids = Contact.where(email: contact.email).where('created_at > ?', time).pluck(:id)
r = ValidationEvent.where(validation_eventable_id: contact_ids).order(created_at: :desc) r = ValidationEvent.where(validation_eventable_id: contact_ids).order(created_at: :desc)
# return false if r[0].success == false
r.present? r.present?
end end

View file

@ -12,7 +12,7 @@ class ValidationEvent < ApplicationRecord
INVALID_EVENTS_COUNT_BY_LEVEL = { INVALID_EVENTS_COUNT_BY_LEVEL = {
regex: 1, regex: 1,
mx: 5, mx: 2,
smtp: 1, smtp: 1,
}.freeze }.freeze

View file

@ -21,7 +21,7 @@ namespace :verify_email do
contacts = prepare_contacts(options) contacts = prepare_contacts(options)
logger.info 'No contacts to check email selected' and next if contacts.blank? logger.info 'No contacts to check email selected' and next if contacts.blank?
contacts.find_each do |contact| contacts.each do |contact|
VerifyEmailsJob.set(wait_until: spam_protect_timeout(options)).perform_later( VerifyEmailsJob.set(wait_until: spam_protect_timeout(options)).perform_later(
contact_id: contact.id, contact_id: contact.id,
check_level: check_level(options) check_level: check_level(options)
@ -58,12 +58,19 @@ def prepare_contacts(options)
validation_events_ids = ValidationEvent.where('created_at > ?', time).pluck(:validation_eventable_id) validation_events_ids = ValidationEvent.where('created_at > ?', time).pluck(:validation_eventable_id)
# Contact.where.not(id: validation_events_ids) + Contact.where(id: failed_contacts) # Contact.where.not(id: validation_events_ids) + Contact.where(id: failed_contacts)
Contact.where.not(id: validation_events_ids) Contact.where.not(id: validation_events_ids) | failed_contacts
end end
end end
def failed_contacts def failed_contacts
ValidationEvent.failed.pluck(:id) failed_contacts = []
failed_validations_ids = ValidationEvent.failed.pluck(:validation_eventable_id)
contacts = Contact.where(id: failed_validations_ids)
contacts.each do |contact|
failed_contacts << contact unless contact.validation_events.last.success
end
failed_contacts
end end
def contacts_by_domain(domain_name) def contacts_by_domain(domain_name)

View file

@ -70,22 +70,19 @@ class VerifyEmailTaskTest < ActiveJob::TestCase
assert_equal ValidationEvent.count, Contact.count - 1 assert_equal ValidationEvent.count, Contact.count - 1
end end
# def test_should_verify_again_contact_which_has_faield_verification def test_should_verify_again_contact_which_has_faield_verification
# expired_date = Time.now - ValidationEvent::VALIDATION_PERIOD - 1.day assert_equal ValidationEvent.count, 0
# run_task
# assert_equal ValidationEvent.count, 0 assert_equal Contact.count, 9
# run_task assert_equal ValidationEvent.count, 8 # Contact has duplicate email and it is skip
# assert_equal Contact.count, 9
# assert_equal ValidationEvent.count, 8 # Contact has duplicate email and it is skip contact = contacts(:john)
# v = ValidationEvent.find_by(validation_eventable_id: contact.id)
# contact = contacts(:john) v.update!(success: false)
# v = ValidationEvent.find_by(validation_eventable_id: contact.id)
# v.update!(success: false) run_task
# assert_equal ValidationEvent.all.count, 9
# run_task end
# binding.pry
# assert_equal ValidationEvent.all.count, 9
# end
def test_should_verify_contact_which_has_expired_date_of_verification def test_should_verify_contact_which_has_expired_date_of_verification
expired_date = Time.now - ValidationEvent::VALIDATION_PERIOD - 1.day expired_date = Time.now - ValidationEvent::VALIDATION_PERIOD - 1.day
@ -103,6 +100,26 @@ class VerifyEmailTaskTest < ActiveJob::TestCase
assert_equal ValidationEvent.all.count, 9 assert_equal ValidationEvent.all.count, 9
end end
def test_should_set_fd_for_domains_which_related_to_failed_emails
assert_equal ValidationEvent.count, 0
run_task
assert_equal Contact.count, 9
assert_equal ValidationEvent.count, 8 # Contact has duplicate email and it is skip
contact = contacts(:john)
v = ValidationEvent.find_by(validation_eventable_id: contact.id)
v.update!(success: false)
4.times do
contact.validation_events << v.dup
end
run_task
assert_equal ValidationEvent.all.count, 13
assert contact.domains.last.force_delete_scheduled?
end
def test_tasks_verifies_emails def test_tasks_verifies_emails
capture_io { run_task } capture_io { run_task }