added possebility to recheck invalid contacts and also remove old records

This commit is contained in:
olegphenomenon 2021-12-17 16:00:08 +02:00
parent 1ec79afb11
commit 761ce9bd6d
3 changed files with 44 additions and 10 deletions

View file

@ -16,6 +16,7 @@ module Actions
maybe_update_ident if ident.present?
maybe_attach_legal_doc
maybe_change_email
maybe_filtering_old_failed_records
commit
end
@ -35,6 +36,15 @@ module Actions
true
end
def maybe_filtering_old_failed_records
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
return if Contact.address_processing?

View file

@ -11,6 +11,7 @@ module Actions
def call
result = check_email(email)
save_result(result)
filtering_old_failed_records(result)
result.success ? log_success : log_failure(result)
result.success
end
@ -25,6 +26,29 @@ module Actions
Rails.env.test? && check_level == 'smtp' ? :mx : check_level.to_sym
end
def filtering_old_failed_records(result)
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
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
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)
validation_eventable.validation_events.create(validation_event_attrs(result))
rescue ActiveRecord::RecordNotSaved