Add removing old records for validation events

This commit is contained in:
dinsmol 2022-02-19 22:43:05 +03:00
parent 4b21b864f0
commit 294b60ebdc
2 changed files with 8 additions and 3 deletions

View file

@ -12,12 +12,17 @@ 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

View file

@ -6,7 +6,7 @@
# For email_validation event kind also check_level (regex/mx/smtp) is stored in the event_data
class ValidationEvent < ApplicationRecord
enum event_type: ValidationEvent::EventType::TYPES, _suffix: true
VALIDATION_PERIOD = 1.year.freeze
VALIDATION_PERIOD = 4.month.freeze
VALID_CHECK_LEVELS = %w[regex mx smtp].freeze
VALID_EVENTS_COUNT_THRESHOLD = 5
MX_CHECK = 3
@ -27,7 +27,7 @@ class ValidationEvent < ApplicationRecord
belongs_to :validation_eventable, polymorphic: true
scope :recent, -> { where('created_at < ?', Time.zone.now - VALIDATION_PERIOD) }
scope :old_records, -> { where('created_at < ?', Time.zone.now - VALIDATION_PERIOD) }
scope :successful, -> { where(success: true) }
scope :failed, -> { where(success: false) }
scope :regex, -> { where('event_data @> ?', { 'check_level': 'regex' }.to_json) }
@ -38,7 +38,7 @@ class ValidationEvent < ApplicationRecord
after_create :check_for_force_delete
def self.validated_ids_by(klass)
recent.successful.where('validation_eventable_type = ?', klass)
old_records.successful.where('validation_eventable_type = ?', klass)
.pluck(:validation_eventable_id)
end