Class: Longleaf::PreserveEvent
- Inherits:
-
Object
- Object
- Longleaf::PreserveEvent
- Includes:
- EventStatusTracking, Logging
- Defined in:
- lib/longleaf/events/preserve_event.rb
Overview
Verify event for a single file
Instance Method Summary collapse
-
#initialize(file_rec:, app_manager:, force: false) ⇒ PreserveEvent
constructor
A new instance of PreserveEvent.
-
#perform ⇒ Object
Perform a preserve event on the given file, updating its metadata record if any services were executed.
Methods included from EventStatusTracking
#record_failure, #record_success, #return_status, #track_failure, #track_status, #track_success
Methods included from Logging
#initialize_logger, initialize_logger, #logger, logger
Constructor Details
#initialize(file_rec:, app_manager:, force: false) ⇒ PreserveEvent
Returns a new instance of PreserveEvent
15 16 17 18 19 20 21 22 |
# File 'lib/longleaf/events/preserve_event.rb', line 15 def initialize(file_rec:, app_manager:, force: false) raise ArgumentError.new('Must provide a file_rec parameter') if file_rec.nil? raise ArgumentError.new('Must provide an ApplicationConfigManager') if app_manager.nil? @app_manager = app_manager @file_rec = file_rec @force = force end |
Instance Method Details
#perform ⇒ Object
Perform a preserve event on the given file, updating its metadata record if any services were executed.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/longleaf/events/preserve_event.rb', line 25 def perform storage_loc = @file_rec.storage_location service_manager = @app_manager.service_manager md_rec = @file_rec. f_path = @file_rec.path logger.info("Performing preserve event on #{@file_rec.path}") needs_persist = false begin if !File.exist?(f_path) # Need to persist metadata to avoid repeating processing of this file too soon. needs_persist = true record_failure(EventNames::PRESERVE, f_path, "File is registered but missing.") return return_status end # get the list of services applicable to this location and event service_manager.list_services(location: storage_loc.name, event: EventNames::PRESERVE).each do |service_name| # Skip over this service if it does not need to be run, unless force flag active unless @force || service_manager.service_needed?(service_name, md_rec) logger.debug("Service #{service_name} not needed for file '#{@file_rec.path}', skipping") next end begin logger.info("Performing preserve service #{service_name} for #{@file_rec.path}") needs_persist = true # execute the service service_manager.perform_service(service_name, @file_rec, EventNames::PRESERVE) # record the outcome @file_rec..update_service_as_performed(service_name) record_success(EventNames::PRESERVE, f_path, nil, service_name) rescue PreservationServiceError => e @file_rec..update_service_as_failed(service_name) record_failure(EventNames::PRESERVE, f_path, e., service_name) rescue StorageLocationUnavailableError => e raise e rescue StandardError => e @file_rec..update_service_as_failed(service_name) record_failure(EventNames::PRESERVE, f_path, nil, service_name, error: e) return return_status end end ensure # persist the metadata out to file if any services were executed if needs_persist # persist the metadata @app_manager.md_manager.persist(@file_rec) end end return_status end |