mirror of
https://github.com/internetee/registry.git
synced 2025-07-27 21:16:12 +02:00
Add logging to archiving process
This commit is contained in:
parent
b2dab0d316
commit
816102130b
3 changed files with 20 additions and 7 deletions
|
@ -9,12 +9,16 @@ module Concerns
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def archivable?
|
def archivable?(post: false)
|
||||||
inactive?
|
inactive = inactive?
|
||||||
|
|
||||||
|
log("Found archivable contact id(#{id}), code (#{code})") if inactive && !post
|
||||||
|
|
||||||
|
inactive
|
||||||
end
|
end
|
||||||
|
|
||||||
def archive
|
def archive
|
||||||
raise 'Contact cannot be archived' unless archivable?
|
raise 'Contact cannot be archived' unless archivable?(post: true)
|
||||||
|
|
||||||
destroy!
|
destroy!
|
||||||
end
|
end
|
||||||
|
@ -32,6 +36,11 @@ module Concerns
|
||||||
def inactivity_period
|
def inactivity_period
|
||||||
Setting.orphans_contacts_in_months.months
|
Setting.orphans_contacts_in_months.months
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def log(msg)
|
||||||
|
@logger ||= Logger.new(STDOUT)
|
||||||
|
@logger.info(msg)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,8 +7,15 @@ class InactiveContacts
|
||||||
|
|
||||||
def archive
|
def archive
|
||||||
contacts.each do |contact|
|
contacts.each do |contact|
|
||||||
|
log("Archiving contact: id(#{contact.id}), code(#{contact.code})")
|
||||||
|
|
||||||
contact.archive
|
contact.archive
|
||||||
yield contact if block_given?
|
yield contact if block_given?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def log(msg)
|
||||||
|
@logger ||= Logger.new(STDOUT)
|
||||||
|
@logger.info(msg)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,13 +2,10 @@ namespace :contacts do
|
||||||
desc 'Archives inactive contacts'
|
desc 'Archives inactive contacts'
|
||||||
|
|
||||||
task archive: :environment do
|
task archive: :environment do
|
||||||
|
puts 'Starting to gather archivable contacts'
|
||||||
inactive_contacts = InactiveContacts.new
|
inactive_contacts = InactiveContacts.new
|
||||||
archived_contacts = inactive_contacts.archive
|
archived_contacts = inactive_contacts.archive
|
||||||
|
|
||||||
archived_contacts.each do |contact|
|
|
||||||
puts "Contact ##{contact.id} (code: #{contact.code}) is archived"
|
|
||||||
end
|
|
||||||
|
|
||||||
puts "Archived total: #{archived_contacts.count}"
|
puts "Archived total: #{archived_contacts.count}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue