mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 18:26:06 +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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue