mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 05:26:17 +02:00
Add rake task optional args
This commit is contained in:
parent
be0ac715b1
commit
b1afdbf50e
4 changed files with 39 additions and 18 deletions
|
@ -1,22 +1,25 @@
|
|||
class ValidationEventCheckForceDeleteJob < ApplicationJob
|
||||
def perform(contact_id)
|
||||
@contact = Contact.find(contact_id)
|
||||
email = @contact.email
|
||||
class CheckForceDeleteJob < ApplicationJob
|
||||
def perform(contact_ids)
|
||||
contacts = Contact.find(contact_ids)
|
||||
|
||||
if @contact.need_to_start_force_delete?
|
||||
Domains::ForceDeleteEmail::Base.run(email: email)
|
||||
elsif @contact.need_to_lift_force_delete?
|
||||
domain_list(email).each { |domain| refresh_status_notes(domain) }
|
||||
contacts.each do |contact|
|
||||
email = contact.email
|
||||
|
||||
if contact.need_to_start_force_delete?
|
||||
Domains::ForceDeleteEmail::Base.run(email: email)
|
||||
elsif contact.need_to_lift_force_delete?
|
||||
domain_list(email).each { |domain| refresh_status_notes(contact, domain) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def refresh_status_notes(domain)
|
||||
def refresh_status_notes(contact, domain)
|
||||
force_delete_emails = domain.status_notes[DomainStatus::FORCE_DELETE]
|
||||
return unless force_delete_emails
|
||||
|
||||
force_delete_emails.slice!(@contact.email_history)
|
||||
force_delete_emails.slice!(contact.email_history)
|
||||
force_delete_emails.lstrip!
|
||||
domain.save(validate: false)
|
||||
|
|
@ -1,11 +1,29 @@
|
|||
desc 'Check Force Delete'
|
||||
task check_force_delete: :environment do
|
||||
task :check_force_delete, %i[batch batch_size batches_delay] => :environment do |_t, args|
|
||||
args.with_defaults(batch: false, batch_size: 1_000, batches_delay: 15)
|
||||
|
||||
batch = ActiveModel::Type::Boolean.new.cast(args[:batch])
|
||||
batch_size = args[:batch_size].to_i
|
||||
batches_delay = args[:batches_delay].to_i.minutes
|
||||
|
||||
invalid_contacts = Contact.joins(:validation_events).select do |contact|
|
||||
events = contact.validation_events
|
||||
events.mx.count >= 3 || events.regex.present?
|
||||
end.uniq(&:id)
|
||||
mx = events.mx.select(&:failed?).count >= ValidationEvent::MX_CHECK
|
||||
regex = events.regex.select(&:failed?).present?
|
||||
|
||||
invalid_contacts.each do |contact|
|
||||
ValidationEventCheckForceDeleteJob.perform_later(contact.id)
|
||||
(contact.need_to_start_force_delete? || contact.need_to_lift_force_delete?) && (mx || regex)
|
||||
end.uniq
|
||||
|
||||
if batch
|
||||
waiting_minutes = 0.minutes
|
||||
|
||||
invalid_contacts.find_in_batches(batch_size: batch_size) do |contact_batches|
|
||||
CheckForceDeleteJob.set(wait: waiting_minutes).perform_later(contact_batches)
|
||||
waiting_minutes += batches_delay
|
||||
end
|
||||
else
|
||||
invalid_contacts.each do |contact|
|
||||
CheckForceDeleteJob.perform_later([contact.id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -540,7 +540,7 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
|
||||
def perform_check_force_delete_job(contact_id)
|
||||
perform_enqueued_jobs do
|
||||
ValidationEventCheckForceDeleteJob.perform_now(contact_id)
|
||||
ValidationEventCheckForceDeleteJob.perform_now([contact_id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,7 +27,7 @@ class CheckForceDeleteTaskTest < ActiveSupport::TestCase
|
|||
run_task
|
||||
|
||||
assert_enqueued_jobs 1
|
||||
assert_enqueued_with(job: ValidationEventCheckForceDeleteJob, args: [@contact.id])
|
||||
assert_enqueued_with(job: CheckForceDeleteJob, args: [@contact.id])
|
||||
end
|
||||
|
||||
def test_enque_force_delete_when_invalid_record_by_regex
|
||||
|
@ -35,7 +35,7 @@ class CheckForceDeleteTaskTest < ActiveSupport::TestCase
|
|||
run_task
|
||||
|
||||
assert_enqueued_jobs 1
|
||||
assert_enqueued_with(job: ValidationEventCheckForceDeleteJob, args: [@invalid_contact.id])
|
||||
assert_enqueued_with(job: CheckForceDeleteJob, args: [@invalid_contact.id])
|
||||
end
|
||||
|
||||
private
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue