Log deleted contacts to file, don't send poll message on initial cycle

This commit is contained in:
Karl Erik Õunapuu 2020-09-16 11:13:50 +03:00
parent ab1fa9064e
commit 7e9a3250bd
No known key found for this signature in database
GPG key ID: C9DD647298A34764
3 changed files with 17 additions and 4 deletions

View file

@ -17,12 +17,13 @@ module Concerns
inactive inactive
end end
def archive(verified: false, notify: true) def archive(verified: false, notify: true, extra_log: false)
unless verified unless verified
raise 'Contact cannot be archived' unless archivable?(post: true) raise 'Contact cannot be archived' unless archivable?(post: true)
end end
notify_registrar_about_archivation if notify notify_registrar_about_archivation if notify
write_to_registrar_log if extra_log
destroy! destroy!
end end
@ -51,6 +52,17 @@ module Concerns
@log ||= Logger.new(STDOUT) @log ||= Logger.new(STDOUT)
@log.info(msg) @log.info(msg)
end end
def write_to_registrar_log
registrar_name = registrar.accounting_customer_code
archive_path = ENV['contact_archivation_log_file_dir']
registrar_log_path = "#{archive_path}/#{registrar_name}.txt"
FileUtils.mkdir_p(archive_path) unless Dir.exist?(archive_path)
f = File.new(registrar_log_path, 'a+')
f.write("#{code}\n")
f.close
end
end end
end end
end end

View file

@ -154,6 +154,7 @@ lhv_ca_file: # Needed only in dev mode
lhv_dev_mode: 'false' lhv_dev_mode: 'false'
epp_session_timeout_seconds: '300' epp_session_timeout_seconds: '300'
contact_archivation_log_file_dir:
# Since the keys for staging are absent from the repo, we need to supply them separate for testing. # Since the keys for staging are absent from the repo, we need to supply them separate for testing.
test: test:

View file

@ -1,9 +1,9 @@
namespace :contacts do namespace :contacts do
desc 'Archives inactive contacts' desc 'Archives inactive contacts'
task :archive, [:track_id] => [:environment] do |_t, args| task :archive, %i[track_id initial_run] => [:environment] do |_t, args|
unlinked_contacts = contacts_start_point(args[:track_id]) unlinked_contacts = contacts_start_point(args[:track_id])
initial_run = args[:initial_run] == true || args[:initial_run] == 'true'
counter = 0 counter = 0
log("Found #{unlinked_contacts.count} unlinked contacts. Starting to archive.") log("Found #{unlinked_contacts.count} unlinked contacts. Starting to archive.")
@ -11,7 +11,7 @@ namespace :contacts do
next unless contact.archivable? next unless contact.archivable?
log("Archiving contact: id(#{contact.id}), code(#{contact.code})") log("Archiving contact: id(#{contact.id}), code(#{contact.code})")
contact.archive(verified: true) contact.archive(verified: true, notify: !initial_run, extra_log: initial_run)
counter += 1 counter += 1
end end