mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 09:27:19 +02:00
119627029-task_moved_into_cronjob
This commit is contained in:
parent
77de3ada8c
commit
2f1b255fc1
3 changed files with 12 additions and 14 deletions
|
@ -132,4 +132,9 @@ class DomainCron
|
|||
)
|
||||
end
|
||||
|
||||
def self.delete_legal_doc_duplicates
|
||||
Rake::Task['legal_doc:remove_duplicates'].reenable
|
||||
Rake::Task['legal_doc:remove_duplicates'].invoke
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -32,27 +32,20 @@ class LegalDocument < ActiveRecord::Base
|
|||
|
||||
|
||||
def save_to_filesystem
|
||||
digest = Digest::SHA1.new
|
||||
binary = Base64.decode64(body)
|
||||
ld = LegalDocument.find_by(checksum: digest.update(binary))
|
||||
|
||||
if ld.nil?
|
||||
loop do
|
||||
loop do
|
||||
rand = SecureRandom.random_number.to_s.last(4)
|
||||
next if rand.to_i == 0 || rand.length < 4
|
||||
|
||||
dir = "#{ENV['legal_documents_dir']}/#{Time.zone.now.strftime('%Y/%m/%d')}"
|
||||
FileUtils.mkdir_p(dir, mode: 0775)
|
||||
self.path = "#{dir}/#{Time.zone.now.to_formatted_s(:number)}_#{rand}.#{document_type}"
|
||||
break unless File.file?(path)
|
||||
end
|
||||
|
||||
File.open(path, 'wb') { |f| f.write(binary) } unless Rails.env.test?
|
||||
self.path = path
|
||||
|
||||
else
|
||||
self.path = ld.path
|
||||
end
|
||||
|
||||
File.open(path, 'wb') { |f| f.write(binary) } unless Rails.env.test?
|
||||
self.path = path
|
||||
|
||||
end
|
||||
|
||||
def calc_checksum
|
||||
|
|
|
@ -3,7 +3,7 @@ namespace :legal_doc do
|
|||
desc 'Legal documents duplicates fix'
|
||||
task all: :environment do
|
||||
Rake::Task['legal_doc:generate_hash'].invoke
|
||||
Rake::Task['legal_doc:remove_dublicates'].invoke
|
||||
Rake::Task['legal_doc:remove_duplicates'].invoke
|
||||
end
|
||||
|
||||
desc 'Generate hash'
|
||||
|
@ -24,7 +24,7 @@ namespace :legal_doc do
|
|||
end
|
||||
|
||||
desc 'Remove duplicates'
|
||||
task remove_dublicates: :environment do
|
||||
task remove_duplicates: :environment do
|
||||
|
||||
start = Time.zone.now.to_f
|
||||
puts '-----> Removing legal documents duplicates'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue