Class: Longleaf::DeregisterCommand

Inherits:
Object
  • Object
show all
Includes:
EventStatusTracking
Defined in:
lib/longleaf/commands/deregister_command.rb

Overview

Command for deregistering files with longleaf

Instance Method Summary collapse

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(app_manager) ⇒ DeregisterCommand

Returns a new instance of DeregisterCommand.



12
13
14
# File 'lib/longleaf/commands/deregister_command.rb', line 12

def initialize(app_manager)
  @app_manager = app_manager
end

Instance Method Details

#execute(file_selector:, force: false) ⇒ Integer

Execute the deregister command on the given parameters

Parameters:

  • file_selector (FileSelector)

    selector for files to deregister

  • force (Boolean) (defaults to: false)

    force flag

Returns:

  • (Integer)

    status code



20
21
22
23
24
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
# File 'lib/longleaf/commands/deregister_command.rb', line 20

def execute(file_selector:, force: false)
  start_time = Time.now
  logger.info('Performing deregister command')
  begin
    # Perform deregister events on each of the file paths provided
    loop do
      f_path = file_selector.next_path
      break if f_path.nil?

      storage_location = @app_manager.location_manager.get_location_by_path(f_path)

      file_rec = FileRecord.new(f_path, storage_location)
      unless file_rec.
        raise DeregistrationError.new("Cannot deregister #{f_path}, file is not registered.")
      end

      @app_manager.md_manager.load(file_rec)

      event = DeregisterEvent.new(file_rec: file_rec, force: force, app_manager: @app_manager)
      track_status(event.perform)
    end
  rescue RegistrationError, DeregistrationError, InvalidStoragePathError, StorageLocationUnavailableError => err
    record_failure(EventNames::DEREGISTER, nil, err.message)
  rescue => err
    record_failure(EventNames::DEREGISTER, error: err)
  end

  logger.info("Completed deregister command in #{Time.now - start_time}s")
  return_status
end