mirror of
https://github.com/internetee/registry.git
synced 2025-07-29 22:16:19 +02:00
Task remove all old validation event records
This commit is contained in:
parent
bbc1380e46
commit
4dcd6d765c
5 changed files with 28 additions and 53 deletions
|
@ -12,17 +12,12 @@ module Actions
|
|||
result = check_email(email)
|
||||
save_result(result)
|
||||
filtering_old_failed_records(result)
|
||||
remove_old_records!
|
||||
result.success ? log_success : log_failure(result)
|
||||
result.success
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def remove_old_records!
|
||||
validation_eventable.validation_events.old_records.destroy_all
|
||||
end
|
||||
|
||||
def check_email(parsed_email)
|
||||
Truemail.validate(parsed_email, with: calculate_check_level).result
|
||||
end
|
||||
|
@ -53,14 +48,10 @@ module Actions
|
|||
|
||||
if !result.success && @check_level == 'mx'
|
||||
result_validation = Actions::AAndAaaaEmailValidation.call(email: @email, value: 'A')
|
||||
output_a_and_aaaa_validation_results(email: @email,
|
||||
result: result_validation,
|
||||
type: 'A')
|
||||
output_a_and_aaaa_validation_results(email: @email, result: result_validation, type: 'A')
|
||||
|
||||
result_validation = Actions::AAndAaaaEmailValidation.call(email: @email, value: 'AAAA') if result_validation.empty?
|
||||
output_a_and_aaaa_validation_results(email: @email,
|
||||
result: result_validation,
|
||||
type: 'AAAA')
|
||||
output_a_and_aaaa_validation_results(email: @email, result: result_validation, type: 'AAAA')
|
||||
result.success = result_validation.present?
|
||||
end
|
||||
|
||||
|
|
|
@ -20,10 +20,6 @@ class VerifyEmailsJob < ApplicationJob
|
|||
|
||||
private
|
||||
|
||||
def contact_not_found(contact_id)
|
||||
raise StandardError, "Contact with contact_id #{contact_id} not found"
|
||||
end
|
||||
|
||||
def validate_check_level(check_level)
|
||||
return if valid_check_levels.include? check_level
|
||||
|
||||
|
@ -38,10 +34,6 @@ class VerifyEmailsJob < ApplicationJob
|
|||
ValidationEvent::VALID_CHECK_LEVELS
|
||||
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?
|
||||
|
||||
|
|
|
@ -20,11 +20,11 @@ namespace :verify_email do
|
|||
hash: opts_hash)
|
||||
email_contacts = prepare_contacts(options)
|
||||
email_contacts.each do |email|
|
||||
VerifyEmailsJob.set(wait_until: spam_protect_timeout(options)).perform_later(
|
||||
email: email,
|
||||
check_level: check_level(options)
|
||||
)
|
||||
VerifyEmailsJob.set(wait_until: spam_protect_timeout(options))
|
||||
.perform_later(email: email, check_level: check_level(options))
|
||||
end
|
||||
|
||||
ValidationEvent.old_records.destroy_all
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -40,10 +40,6 @@ def spam_protect_timeout(options)
|
|||
spam_protect(options) ? 0.seconds : SPAM_PROTECT_TIMEOUT
|
||||
end
|
||||
|
||||
def logger
|
||||
@logger ||= ActiveSupport::TaggedLogging.new(Syslog::Logger.new('registry'))
|
||||
end
|
||||
|
||||
def prepare_contacts(options)
|
||||
if options[:domain_name].present?
|
||||
contacts_by_domain(options[:domain_name])
|
||||
|
|
|
@ -95,27 +95,4 @@ class EmailCheckTest < ActiveSupport::TestCase
|
|||
assert_equal @contact.validation_events.count, 1
|
||||
assert @contact.validation_events.last.success
|
||||
end
|
||||
|
||||
def test_should_remove_old_validation_records
|
||||
trumail_results = OpenStruct.new(success: false,
|
||||
email: @contact.email,
|
||||
domain: "box.tests",
|
||||
errors: {:mx=>"target host(s) not found"},
|
||||
)
|
||||
|
||||
Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_results)
|
||||
Spy.on_instance_method(Actions::AAndAaaaEmailValidation, :call).and_return([true])
|
||||
|
||||
action = Actions::EmailCheck.new(email: @contact.email,
|
||||
validation_eventable: @contact,
|
||||
check_level: 'regex')
|
||||
|
||||
|
||||
action.call
|
||||
assert_equal @contact.validation_events.count, 1
|
||||
|
||||
travel_to(Time.zone.now + ::ValidationEvent::VALIDATION_PERIOD + 1.minute)
|
||||
action.call
|
||||
assert_equal @contact.validation_events.count, 1
|
||||
end
|
||||
end
|
||||
|
|
|
@ -116,13 +116,32 @@ class VerifyEmailTaskTest < ActiveJob::TestCase
|
|||
)
|
||||
Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_results)
|
||||
|
||||
1.times do
|
||||
run_task
|
||||
end
|
||||
run_task
|
||||
|
||||
assert contact.domains.last.force_delete_scheduled?
|
||||
end
|
||||
|
||||
def test_should_remove_old_validation_records
|
||||
trumail_results = OpenStruct.new(success: false,
|
||||
email: @contact.email,
|
||||
domain: 'box.tests',
|
||||
errors: { mx: 'target host(s) not found' })
|
||||
|
||||
Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_results)
|
||||
Spy.on_instance_method(Actions::AAndAaaaEmailValidation, :call).and_return([true])
|
||||
|
||||
Actions::EmailCheck.new(email: @contact.email,
|
||||
validation_eventable: @contact,
|
||||
check_level: 'regex').call
|
||||
|
||||
travel_to(Time.zone.now + ::ValidationEvent::VALIDATION_PERIOD + 1.minute)
|
||||
assert_equal ValidationEvent.old_records.count, 1
|
||||
|
||||
run_task
|
||||
|
||||
assert_predicate ValidationEvent.old_records.count, :zero?
|
||||
end
|
||||
|
||||
def run_task
|
||||
perform_enqueued_jobs do
|
||||
Rake::Task['verify_email:check_all'].execute
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue