Class: Maintenance::ExportPacketMaintenance

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

Instance Method Summary collapse

Methods inherited from BaseService

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

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#processObject



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

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).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