mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 20:55:44 +02:00
contacts:archive: delete orphaned once it's discovered / allow to start query from specific contact_id
This commit is contained in:
parent
bbbb3d5367
commit
fa6ebd9cda
2 changed files with 23 additions and 5 deletions
|
@ -1,10 +1,27 @@
|
||||||
namespace :contacts do
|
namespace :contacts do
|
||||||
desc 'Archives inactive contacts'
|
desc 'Archives inactive contacts'
|
||||||
|
|
||||||
task archive: :environment do
|
task :archive, [:track_id] => [:environment] do |_t, args|
|
||||||
inactive_contacts = InactiveContacts.new
|
unlinked_contacts = contacts_start_point(args[:track_id])
|
||||||
archived_contacts = inactive_contacts.archive(verified: true)
|
|
||||||
|
|
||||||
puts "Archived total: #{archived_contacts.count}"
|
counter = 0
|
||||||
|
puts "Found #{unlinked_contacts.count} unlinked contacts. Starting to archive."
|
||||||
|
|
||||||
|
unlinked_contacts.each do |contact|
|
||||||
|
next unless contact.archivable?
|
||||||
|
|
||||||
|
puts "Archiving contact: id(#{contact.id}), code(#{contact.code})"
|
||||||
|
contact.archive(verified: true)
|
||||||
|
counter += 1
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "Archived total: #{counter}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def contacts_start_point(track_id = nil)
|
||||||
|
puts "Starting to find archivable contacts WHERE CONTACT_ID > #{track_id}" if track_id
|
||||||
|
return Contact.unlinked unless track_id
|
||||||
|
|
||||||
|
Contact.unlinked.where("id > #{track_id}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,7 +13,8 @@ class ArchiveContactsTaskTest < ActiveSupport::TestCase
|
||||||
contact = archivable_contact
|
contact = archivable_contact
|
||||||
eliminate_effect_of_all_contacts_except(contact)
|
eliminate_effect_of_all_contacts_except(contact)
|
||||||
|
|
||||||
expected_output = "Found archivable contact id(#{contact.id}), code (#{contact.code})\n" \
|
expected_output = "Found 1 unlinked contacts. Starting to archive.\n" \
|
||||||
|
"Found archivable contact id(#{contact.id}), code (#{contact.code})\n" \
|
||||||
"Archiving contact: id(#{contact.id}), code(#{contact.code})\n" \
|
"Archiving contact: id(#{contact.id}), code(#{contact.code})\n" \
|
||||||
"Archived total: 1\n"
|
"Archived total: 1\n"
|
||||||
assert_output(expected_output) { run_task }
|
assert_output(expected_output) { run_task }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue