Skip to content

Commit

Permalink
Log deleted contacts to file, don't send poll message on initial cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
karlerikounapuu committed Sep 16, 2020
1 parent ab1fa90 commit 9cc25e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 13 additions & 1 deletion app/models/concerns/contact/archivable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ def archivable?(post: false)
inactive
end

def archive(verified: false, notify: true)
def archive(verified: false, notify: true, extra_log: false)
unless verified
raise 'Contact cannot be archived' unless archivable?(post: true)
end

notify_registrar_about_archivation if notify
write_to_registrar_log if extra_log
destroy!
end

Expand Down Expand Up @@ -51,6 +52,17 @@ def log(msg)
@log ||= Logger.new(STDOUT)
@log.info(msg)
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
6 changes: 3 additions & 3 deletions lib/tasks/contacts/archive.rake
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
namespace :contacts do
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])

initial_run = args[:initial_run] == true || args[:initial_run] == 'true'
counter = 0
log("Found #{unlinked_contacts.count} unlinked contacts. Starting to archive.")

unlinked_contacts.each do |contact|
next unless contact.archivable?

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
end

Expand Down

0 comments on commit 9cc25e0

Please sign in to comment.