mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 09:57:23 +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
|
end
|
||||||
|
|
||||||
|
def self.delete_legal_doc_duplicates
|
||||||
|
Rake::Task['legal_doc:remove_duplicates'].reenable
|
||||||
|
Rake::Task['legal_doc:remove_duplicates'].invoke
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,15 +32,11 @@ class LegalDocument < ActiveRecord::Base
|
||||||
|
|
||||||
|
|
||||||
def save_to_filesystem
|
def save_to_filesystem
|
||||||
digest = Digest::SHA1.new
|
|
||||||
binary = Base64.decode64(body)
|
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)
|
rand = SecureRandom.random_number.to_s.last(4)
|
||||||
next if rand.to_i == 0 || rand.length < 4
|
next if rand.to_i == 0 || rand.length < 4
|
||||||
|
|
||||||
dir = "#{ENV['legal_documents_dir']}/#{Time.zone.now.strftime('%Y/%m/%d')}"
|
dir = "#{ENV['legal_documents_dir']}/#{Time.zone.now.strftime('%Y/%m/%d')}"
|
||||||
FileUtils.mkdir_p(dir, mode: 0775)
|
FileUtils.mkdir_p(dir, mode: 0775)
|
||||||
self.path = "#{dir}/#{Time.zone.now.to_formatted_s(:number)}_#{rand}.#{document_type}"
|
self.path = "#{dir}/#{Time.zone.now.to_formatted_s(:number)}_#{rand}.#{document_type}"
|
||||||
|
@ -50,9 +46,6 @@ class LegalDocument < ActiveRecord::Base
|
||||||
File.open(path, 'wb') { |f| f.write(binary) } unless Rails.env.test?
|
File.open(path, 'wb') { |f| f.write(binary) } unless Rails.env.test?
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
||||||
else
|
|
||||||
self.path = ld.path
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def calc_checksum
|
def calc_checksum
|
||||||
|
|
|
@ -3,7 +3,7 @@ namespace :legal_doc do
|
||||||
desc 'Legal documents duplicates fix'
|
desc 'Legal documents duplicates fix'
|
||||||
task all: :environment do
|
task all: :environment do
|
||||||
Rake::Task['legal_doc:generate_hash'].invoke
|
Rake::Task['legal_doc:generate_hash'].invoke
|
||||||
Rake::Task['legal_doc:remove_dublicates'].invoke
|
Rake::Task['legal_doc:remove_duplicates'].invoke
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Generate hash'
|
desc 'Generate hash'
|
||||||
|
@ -24,7 +24,7 @@ namespace :legal_doc do
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Remove duplicates'
|
desc 'Remove duplicates'
|
||||||
task remove_dublicates: :environment do
|
task remove_duplicates: :environment do
|
||||||
|
|
||||||
start = Time.zone.now.to_f
|
start = Time.zone.now.to_f
|
||||||
puts '-----> Removing legal documents duplicates'
|
puts '-----> Removing legal documents duplicates'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue