mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 20:55:44 +02:00
Use log() method instead of puts
This commit is contained in:
parent
dadb8ba88a
commit
5c7e07dbb5
3 changed files with 23 additions and 8 deletions
|
@ -12,7 +12,7 @@ module Concerns
|
|||
def archivable?(post: false)
|
||||
inactive = inactive?
|
||||
|
||||
puts "Found archivable contact id(#{id}), code (#{code})" if inactive && !post
|
||||
log("Found archivable contact id(#{id}), code (#{code})") if inactive && !post
|
||||
|
||||
inactive
|
||||
end
|
||||
|
@ -29,9 +29,9 @@ module Concerns
|
|||
private
|
||||
|
||||
def notify_registrar_about_archivation
|
||||
registrar.notifications.create!(text: I18n.t('contact_has_been_archived',
|
||||
contact_code: code,
|
||||
orphan_months: Setting.orphans_contacts_in_months))
|
||||
registrar.notifications.create!(
|
||||
text: I18n.t('contact_has_been_archived',
|
||||
contact_code: code, orphan_months: Setting.orphans_contacts_in_months))
|
||||
end
|
||||
|
||||
def inactive?
|
||||
|
@ -45,6 +45,11 @@ module Concerns
|
|||
def inactivity_period
|
||||
Setting.orphans_contacts_in_months.months
|
||||
end
|
||||
|
||||
def log(msg)
|
||||
@log ||= Logger.new(STDOUT)
|
||||
@log.info(msg)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,9 +7,14 @@ class InactiveContacts
|
|||
|
||||
def archive(verified: false)
|
||||
contacts.each do |contact|
|
||||
puts "Archiving contact: id(#{contact.id}), code(#{contact.code})"
|
||||
log("Archiving contact: id(#{contact.id}), code(#{contact.code})")
|
||||
contact.archive(verified: verified)
|
||||
yield contact if block_given?
|
||||
end
|
||||
end
|
||||
|
||||
def log(msg)
|
||||
@log ||= Logger.new(STDOUT)
|
||||
@log.info(msg)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,17 +5,17 @@ namespace :contacts do
|
|||
unlinked_contacts = contacts_start_point(args[:track_id])
|
||||
|
||||
counter = 0
|
||||
puts "Found #{unlinked_contacts.count} unlinked contacts. Starting to archive."
|
||||
log("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})"
|
||||
log("Archiving contact: id(#{contact.id}), code(#{contact.code})")
|
||||
contact.archive(verified: true)
|
||||
counter += 1
|
||||
end
|
||||
|
||||
puts "Archived total: #{counter}"
|
||||
log("Archived total: #{counter}")
|
||||
end
|
||||
|
||||
def contacts_start_point(track_id = nil)
|
||||
|
@ -24,4 +24,9 @@ namespace :contacts do
|
|||
|
||||
Contact.unlinked.where("id > #{track_id}")
|
||||
end
|
||||
|
||||
def log(msg)
|
||||
@log ||= Logger.new(STDOUT)
|
||||
@log.info(msg)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue