mirror of
https://github.com/internetee/registry.git
synced 2025-06-07 21:25:39 +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)
|
def archivable?(post: false)
|
||||||
inactive = inactive?
|
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
|
inactive
|
||||||
end
|
end
|
||||||
|
@ -29,9 +29,9 @@ module Concerns
|
||||||
private
|
private
|
||||||
|
|
||||||
def notify_registrar_about_archivation
|
def notify_registrar_about_archivation
|
||||||
registrar.notifications.create!(text: I18n.t('contact_has_been_archived',
|
registrar.notifications.create!(
|
||||||
contact_code: code,
|
text: I18n.t('contact_has_been_archived',
|
||||||
orphan_months: Setting.orphans_contacts_in_months))
|
contact_code: code, orphan_months: Setting.orphans_contacts_in_months))
|
||||||
end
|
end
|
||||||
|
|
||||||
def inactive?
|
def inactive?
|
||||||
|
@ -45,6 +45,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)
|
||||||
|
@log ||= Logger.new(STDOUT)
|
||||||
|
@log.info(msg)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,9 +7,14 @@ class InactiveContacts
|
||||||
|
|
||||||
def archive(verified: false)
|
def archive(verified: false)
|
||||||
contacts.each do |contact|
|
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)
|
contact.archive(verified: verified)
|
||||||
yield contact if block_given?
|
yield contact if block_given?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def log(msg)
|
||||||
|
@log ||= Logger.new(STDOUT)
|
||||||
|
@log.info(msg)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,17 +5,17 @@ namespace :contacts do
|
||||||
unlinked_contacts = contacts_start_point(args[:track_id])
|
unlinked_contacts = contacts_start_point(args[:track_id])
|
||||||
|
|
||||||
counter = 0
|
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|
|
unlinked_contacts.each do |contact|
|
||||||
next unless contact.archivable?
|
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)
|
contact.archive(verified: true)
|
||||||
counter += 1
|
counter += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "Archived total: #{counter}"
|
log("Archived total: #{counter}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def contacts_start_point(track_id = nil)
|
def contacts_start_point(track_id = nil)
|
||||||
|
@ -24,4 +24,9 @@ namespace :contacts do
|
||||||
|
|
||||||
Contact.unlinked.where("id > #{track_id}")
|
Contact.unlinked.where("id > #{track_id}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def log(msg)
|
||||||
|
@log ||= Logger.new(STDOUT)
|
||||||
|
@log.info(msg)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue