mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 21:46:24 +02:00
Add removing old records for validation events
This commit is contained in:
parent
4b21b864f0
commit
294b60ebdc
2 changed files with 8 additions and 3 deletions
|
@ -12,12 +12,17 @@ module Actions
|
||||||
result = check_email(email)
|
result = check_email(email)
|
||||||
save_result(result)
|
save_result(result)
|
||||||
filtering_old_failed_records(result)
|
filtering_old_failed_records(result)
|
||||||
|
remove_old_records!
|
||||||
result.success ? log_success : log_failure(result)
|
result.success ? log_success : log_failure(result)
|
||||||
result.success
|
result.success
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def remove_old_records!
|
||||||
|
validation_eventable.validation_events.old_records.destroy_all
|
||||||
|
end
|
||||||
|
|
||||||
def check_email(parsed_email)
|
def check_email(parsed_email)
|
||||||
Truemail.validate(parsed_email, with: calculate_check_level).result
|
Truemail.validate(parsed_email, with: calculate_check_level).result
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
# For email_validation event kind also check_level (regex/mx/smtp) is stored in the event_data
|
# For email_validation event kind also check_level (regex/mx/smtp) is stored in the event_data
|
||||||
class ValidationEvent < ApplicationRecord
|
class ValidationEvent < ApplicationRecord
|
||||||
enum event_type: ValidationEvent::EventType::TYPES, _suffix: true
|
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_CHECK_LEVELS = %w[regex mx smtp].freeze
|
||||||
VALID_EVENTS_COUNT_THRESHOLD = 5
|
VALID_EVENTS_COUNT_THRESHOLD = 5
|
||||||
MX_CHECK = 3
|
MX_CHECK = 3
|
||||||
|
@ -27,7 +27,7 @@ class ValidationEvent < ApplicationRecord
|
||||||
|
|
||||||
belongs_to :validation_eventable, polymorphic: true
|
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 :successful, -> { where(success: true) }
|
||||||
scope :failed, -> { where(success: false) }
|
scope :failed, -> { where(success: false) }
|
||||||
scope :regex, -> { where('event_data @> ?', { 'check_level': 'regex' }.to_json) }
|
scope :regex, -> { where('event_data @> ?', { 'check_level': 'regex' }.to_json) }
|
||||||
|
@ -38,7 +38,7 @@ class ValidationEvent < ApplicationRecord
|
||||||
after_create :check_for_force_delete
|
after_create :check_for_force_delete
|
||||||
|
|
||||||
def self.validated_ids_by(klass)
|
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)
|
.pluck(:validation_eventable_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue