2019-05-09 17:10:02 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-23 15:19:08 +02:00
|
|
|
class TempFile < ApplicationRecord
|
2016-02-12 16:52:43 +01:00
|
|
|
validates :session_id, presence: true
|
|
|
|
|
2019-07-05 16:56:05 +02:00
|
|
|
has_one_attached :file
|
2017-05-05 14:54:22 +02:00
|
|
|
|
2018-09-21 17:46:18 +02:00
|
|
|
class << self
|
|
|
|
def destroy_obsolete(temp_file_id)
|
|
|
|
temp_file = find_by_id(temp_file_id)
|
|
|
|
return unless temp_file.present?
|
2019-05-09 17:10:02 +02:00
|
|
|
|
2018-09-21 17:46:18 +02:00
|
|
|
temp_file.destroy!
|
|
|
|
end
|
2017-05-05 14:54:22 +02:00
|
|
|
|
2019-05-09 17:10:02 +02:00
|
|
|
handle_asynchronously :destroy_obsolete, run_at: proc { 7.days.from_now }
|
2018-09-21 17:46:18 +02:00
|
|
|
end
|
2016-02-12 16:52:43 +01:00
|
|
|
end
|