Class: Longleaf::RegisterCommand

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

Overview

Command for registering 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) ⇒ RegisterCommand

Returns a new instance of RegisterCommand.



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

def initialize(app_manager)
  @app_manager = app_manager
end

Instance Method Details

#execute(file_selector:, force: false, digest_provider: nil, physical_provider: nil) ⇒ Integer

Execute the register command on the given parameters

Parameters:

  • file_selector (FileSelector)

    selector for files to register

  • force (Boolean) (defaults to: false)

    force flag

  • digest_provider (ManifestDigestProvider) (defaults to: nil)

    object which provides digests for files being registered

  • physical_provider (PhysicalPathProvider) (defaults to: nil)

    object which provides physical paths for files being registered

Returns:

  • (Integer)

    status code



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
# File 'lib/longleaf/commands/register_command.rb', line 22

def execute(file_selector:, force: false, digest_provider: nil, physical_provider: nil)
  start_time = Time.now
  logger.info('Performing register command')
  begin
    # Perform register 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)

      phys_path = physical_provider.get_physical_path(f_path)
      file_rec = FileRecord.new(f_path, storage_location, nil, phys_path)

      register_event = RegisterEvent.new(file_rec: file_rec, force: force, app_manager: @app_manager,
          digest_provider: digest_provider)
      track_status(register_event.perform)
    end
  rescue InvalidStoragePathError, StorageLocationUnavailableError => err
    record_failure(EventNames::REGISTER, nil, err.message)
  rescue => err
    record_failure(EventNames::REGISTER, error: err)
  end

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