Class: DeleteAttachmentJob

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job
Defined in:
app/sidekiq/delete_attachment_job.rb

Constant Summary collapse

EXPIRATION_TIME =
2.months

Instance Method Summary collapse

Instance Method Details

#performObject



10
11
12
13
14
15
16
# File 'app/sidekiq/delete_attachment_job.rb', line 10

def perform
  FormAttachment.where(
    'created_at < ?', self.class::EXPIRATION_TIME.ago
  ).where(
    type: self.class::ATTACHMENT_CLASSES
  ).where.not(guid: uuids_to_keep).find_each(&:destroy!)
end

#uuids_to_keepObject



18
19
20
21
22
23
24
25
26
# File 'app/sidekiq/delete_attachment_job.rb', line 18

def uuids_to_keep
  uuids = []

  InProgressForm.where(form_id: self.class::FORM_ID).find_each do |in_progress_form|
    uuids += get_uuids(in_progress_form.[:formData])
  end

  uuids
end