Class: Maintenance::ExportPacketMaintenance

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/maintenance/export_packet_maintenance.rb

Overview

Service object: export packet maintenance.

Instance Attribute Summary

Attributes inherited from BaseService

#options

Instance Method Summary collapse

Methods inherited from BaseService

#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #tagged_logger

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#processObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/services/maintenance/export_packet_maintenance.rb', line 4

def process
  PaperTrail.request(whodunnit: 'Maintenance::ExportPacketMaintenance') do
    # Find all packets older than a month and mark them inactive
    ExportedCatalogItemPacket.where(updated_at: ...1.month.ago).find_each do |ecip|
      log_info "Archiving packet #{ecip.id}"
      ecip.update_attribute!(:inactive, true)
    end
    # Two step process to catch manually inactivated packet and by joining with uploads
    # we delete on those that still have to be processed.
    ExportedCatalogItemPacket.joins(:uploads).where(inactive: true).distinct.each do |ecip|
      ecip.uploads.each(&:destroy)
    end
  end
end