mirror of
https://github.com/internetee/registry.git
synced 2025-07-27 21:16:12 +02:00
Refactored and corrected code for domain force delete
This commit is contained in:
parent
316f00cadc
commit
d3bca1434c
10 changed files with 223 additions and 259 deletions
|
@ -3,12 +3,13 @@ require 'rake_option_parser_boilerplate'
|
|||
require 'syslog/logger'
|
||||
require 'active_record'
|
||||
|
||||
SPAM_PROTECT_TIMEOUT = 30.seconds
|
||||
|
||||
namespace :verify_email do
|
||||
# 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
|
||||
SPAM_PROTECT_TIMEOUT = 30.seconds
|
||||
options = {
|
||||
domain_name: nil,
|
||||
check_level: 'mx',
|
||||
|
@ -18,48 +19,48 @@ namespace :verify_email do
|
|||
options = RakeOptionParserBoilerplate.process_args(options: options,
|
||||
banner: banner,
|
||||
hash: opts_hash)
|
||||
|
||||
ValidationEvent.old_records.destroy_all
|
||||
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))
|
||||
end
|
||||
enqueue_email_verification(email_contacts, options)
|
||||
end
|
||||
end
|
||||
|
||||
def check_level(options)
|
||||
options[:check_level]
|
||||
end
|
||||
|
||||
def spam_protect(options)
|
||||
options[:spam_protect]
|
||||
def enqueue_email_verification(email_contacts, options)
|
||||
email_contacts.each do |email|
|
||||
VerifyEmailsJob.set(wait_until: spam_protect_timeout(options))
|
||||
.perform_later(email: email, check_level: options[:check_level])
|
||||
end
|
||||
end
|
||||
|
||||
def spam_protect_timeout(options)
|
||||
spam_protect(options) ? 0.seconds : SPAM_PROTECT_TIMEOUT
|
||||
options[:spam_protect] ? 0.seconds : SPAM_PROTECT_TIMEOUT
|
||||
end
|
||||
|
||||
def prepare_contacts(options)
|
||||
if options[:domain_name].present?
|
||||
contacts_by_domain(options[:domain_name])
|
||||
else
|
||||
time = Time.zone.now - ValidationEvent::VALIDATION_PERIOD
|
||||
validation_events_ids = ValidationEvent.where('created_at > ?', time).distinct.pluck(:validation_eventable_id)
|
||||
|
||||
contacts_emails = Contact.where.not(id: validation_events_ids).pluck(:email)
|
||||
(contacts_emails + failed_email_contacts).uniq
|
||||
unvalidated_and_failed_contacts_emails
|
||||
end
|
||||
end
|
||||
|
||||
def failed_email_contacts
|
||||
failed_contacts = []
|
||||
def unvalidated_and_failed_contacts_emails
|
||||
time = Time.zone.now - ValidationEvent::VALIDATION_PERIOD
|
||||
validation_events_ids = ValidationEvent.where('created_at >= ?', time)
|
||||
.distinct.pluck(:validation_eventable_id)
|
||||
unvalidated_contacts_emails = Contact.where.not(id: validation_events_ids).pluck(:email)
|
||||
(unvalidated_contacts_emails + failed_contacts_emails).uniq
|
||||
end
|
||||
|
||||
def failed_contacts_emails(emails: [])
|
||||
failed_validations_ids = ValidationEvent.failed.distinct.pluck(:validation_eventable_id)
|
||||
contacts = Contact.where(id: failed_validations_ids).includes(:validation_events)
|
||||
contacts.find_each(batch_size: 10_000) do |contact|
|
||||
failed_contacts << contact.email
|
||||
|
||||
Contact.where(id: failed_validations_ids).find_each(batch_size: 10_000) do |contact|
|
||||
emails << contact.email
|
||||
end
|
||||
|
||||
failed_contacts.uniq
|
||||
emails.uniq
|
||||
end
|
||||
|
||||
def contacts_by_domain(domain_name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue