Class: Longleaf::DeregisterEvent
- Inherits:
-
Object
- Object
- Longleaf::DeregisterEvent
- Includes:
- EventStatusTracking
- Defined in:
- lib/longleaf/events/deregister_event.rb
Overview
Event to deregister a file from longleaf
Instance Method Summary collapse
-
#initialize(file_rec:, app_manager:, force: false) ⇒ DeregisterEvent
constructor
A new instance of DeregisterEvent.
-
#perform ⇒ Object
Perform a deregistration event on the given file record.
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) ⇒ DeregisterEvent
Returns a new instance of DeregisterEvent.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/longleaf/events/deregister_event.rb', line 14 def initialize(file_rec:, app_manager:, force: false) raise ArgumentError.new('Must provide a file_rec parameter') if file_rec.nil? raise ArgumentError.new('Parameter file_rec must be a FileRecord') \ unless file_rec.is_a?(FileRecord) raise ArgumentError.new('Must provide an ApplicationConfigManager') if app_manager.nil? raise ArgumentError.new('Parameter app_manager must be an ApplicationConfigManager') \ unless app_manager.is_a?(ApplicationConfigManager) @app_manager = app_manager @file_rec = file_rec @force = force end |
Instance Method Details
#perform ⇒ Object
Perform a deregistration event on the given file record
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/longleaf/events/deregister_event.rb', line 29 def perform begin md_rec = @file_rec. # Only need to deregister a deregistered file if the force flag is provided if md_rec.deregistered? && !@force raise DeregistrationError.new("Unable to deregister '#{@file_rec.path}', it is already deregistered.") end md_rec.deregistered = Time.now.utc.iso8601(3) # persist the metadata @app_manager.md_manager.persist(@file_rec) record_success(EventNames::DEREGISTER, @file_rec.path) rescue DeregistrationError => err record_failure(EventNames::DEREGISTER, @file_rec.path, err.) rescue InvalidStoragePathError => err record_failure(EventNames::DEREGISTER, @file_rec.path, err.) end return_status end |