Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor contact archivation #1146

Merged
merged 22 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
487613d
Refactor inactive contact archivation
Mar 28, 2019
d45e500
Archive contacts every day
Apr 2, 2019
6659c59
Change `log_domains.children` database column's type to `jsonb`
Apr 4, 2019
de8e663
Change `log_domains.children` database column's type to `jsonb`
Apr 4, 2019
73e9dd6
Resolve merge errors
karlerikounapuu Sep 2, 2020
e9f28a6
Merge branch 'refactor-contact-archivation' of https://github.com/int…
karlerikounapuu Sep 2, 2020
3c77566
Resolve some minor CC issues
karlerikounapuu Sep 2, 2020
7a24eab
Fix contact archivation tests
karlerikounapuu Sep 3, 2020
821c52a
Submit only object ID to DomainVersion linked methods instead of full…
karlerikounapuu Sep 3, 2020
6707ca1
Improve determining archivable contacts
karlerikounapuu Sep 3, 2020
28dea2f
Reference orphans_contacts_in_months directly from Settings
karlerikounapuu Sep 3, 2020
b2dab0d
Merge branch 'master' into refactor-contact-archivation
karlerikounapuu Sep 3, 2020
8161021
Add logging to archiving process
karlerikounapuu Sep 3, 2020
11fc484
Don't double check if contact can be archived when ran via Task
karlerikounapuu Sep 3, 2020
bbbb3d5
Improve logging
karlerikounapuu Sep 3, 2020
fa6ebd9
contacts:archive: delete orphaned once it's discovered / allow to sta…
karlerikounapuu Sep 4, 2020
dadb8ba
Send poll message to Registrar after it's contact has been archieved
karlerikounapuu Sep 4, 2020
5c7e07d
Use log() method instead of puts
karlerikounapuu Sep 4, 2020
a5b59f2
Fix CC issues
karlerikounapuu Sep 4, 2020
5330743
Test poll notification is sent to registrar after contact archivation
karlerikounapuu Sep 4, 2020
ab1fa90
Merge remote-tracking branch 'origin/master' into refactor-contact-ar…
karlerikounapuu Sep 16, 2020
7e9a325
Log deleted contacts to file, don't send poll message on initial cycle
karlerikounapuu Sep 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions app/models/concerns/contact/archivable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def archivable
def archivable?(post: false)
inactive = inactive?

log("Found archivable contact id(#{id}), code (#{code})") if inactive && !post
puts "Found archivable contact id(#{id}), code (#{code})" if inactive && !post

inactive
end
Expand All @@ -38,11 +38,6 @@ def inactive?
def inactivity_period
Setting.orphans_contacts_in_months.months
end

def log(msg)
@logger ||= Logger.new(STDOUT)
@logger.info(msg)
end
end
end
end
8 changes: 1 addition & 7 deletions app/models/inactive_contacts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@ def initialize(contacts = Contact.archivable)

def archive(verified: false)
contacts.each do |contact|
log("Archiving contact: id(#{contact.id}), code(#{contact.code})")

puts "Archiving contact: id(#{contact.id}), code(#{contact.code})"
contact.archive(verified: verified)
yield contact if block_given?
end
end

def log(msg)
@logger ||= Logger.new(STDOUT)
@logger.info(msg)
end
end
1 change: 0 additions & 1 deletion lib/tasks/contacts/archive.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ namespace :contacts do
desc 'Archives inactive contacts'

task archive: :environment do
puts 'Starting to gather archivable contacts'
inactive_contacts = InactiveContacts.new
archived_contacts = inactive_contacts.archive(verified: true)

Expand Down
6 changes: 4 additions & 2 deletions test/models/inactive_contacts_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
class InactiveContactsTest < ActiveSupport::TestCase
def test_archives_inactive_contacts
contact_mock = Minitest::Mock.new
contact_mock.expect(:archive, nil)
contact_mock.expect(:archive, nil, [{verified: false}])
contact_mock.expect(:id, 'id')
contact_mock.expect(:code, 'code')

inactive_contacts = InactiveContacts.new([contact_mock])
inactive_contacts.archive

assert_mock contact_mock
end
end
end
3 changes: 2 additions & 1 deletion test/tasks/contacts/archive_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def test_output
contact = archivable_contact
eliminate_effect_of_all_contacts_except(contact)

expected_output = "Contact ##{contact.id} (code: #{contact.code}) is archived\n" \
expected_output = "Found archivable contact id(#{contact.id}), code (#{contact.code})\n" \
"Archiving contact: id(#{contact.id}), code(#{contact.code})\n" \
"Archived total: 1\n"
assert_output(expected_output) { run_task }
end
Expand Down