Merge pull request #2377 from internetee/fixed-looping-validation

fixed looping validation email
This commit is contained in:
Timo Võhmar 2022-05-25 12:20:21 +03:00 committed by GitHub
commit 4a973b8624
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 18 deletions

View file

@ -37,11 +37,12 @@ module Actions
end
def maybe_filtering_old_failed_records
validation_events = contact.validation_events
return unless validation_events.count > 1
validation_events.order!(created_at: :asc)
validation_events.first.destroy while validation_events.count >= 1
if contact.validation_events.count > 1
contact.validation_events.order!(created_at: :asc)
while contact.validation_events.count >= 1
contact.validation_events.first.destroy
end
end
end
def maybe_remove_address

View file

@ -26,21 +26,27 @@ module Actions
Rails.env.test? && check_level == 'smtp' ? :mx : check_level.to_sym
end
def destroy_old_validations(validation_events, minimum_size, check_level)
return unless validation_events.count > minimum_size && @check_level == check_level
validation_events.order!(created_at: :asc)
validation_events.first.destroy while validation_events.count > minimum_size
end
def filtering_old_failed_records(result)
events = validation_eventable.validation_events
if @check_level == "mx" && !result.success && validation_eventable.validation_events.count > 3
validation_eventable.validation_events.order!(created_at: :asc)
while validation_eventable.validation_events.count > 3
validation_eventable.validation_events.first.destroy
end
end
destroy_old_validations(events, ValidationEvent::MX_CHECK, 'mx') unless result.success
if @check_level == "mx" && result.success && validation_eventable.validation_events.count > 1
validation_eventable.validation_events.order!(created_at: :asc)
while validation_eventable.validation_events.count > 1
validation_eventable.validation_events.first.destroy
end
end
destroy_old_validations(events, ValidationEvent::REDEEM_EVENTS_COUNT_BY_LEVEL[:mx], 'mx') if result.success
destroy_old_validations(events, ValidationEvent::REDEEM_EVENTS_COUNT_BY_LEVEL[:smtp], 'smtp')
if @check_level == "smtp" && validation_eventable.validation_events.count > 1
validation_eventable.validation_events.order!(created_at: :asc)
while validation_eventable.validation_events.count > 1
validation_eventable.validation_events.first.destroy
end
end
end
def save_result(result)

View file

@ -4,7 +4,7 @@ require 'syslog/logger'
require 'active_record'
namespace :verify_email do
# bundle exec rake verify_email:check_all -- --domain_name=shop.test --check_level=mx --spam_protect=true
# bundle exec rake verify_email:check_all -- --check_level=mx --spam_protect=true
# bundle exec rake verify_email:check_all -- -dshop.test -cmx -strue
desc 'Starts verifying email jobs with optional check level and spam protection'
task check_all: :environment do