Class: Envoi::Restore::Agent

Inherits:
Mam::Agent show all
Defined in:
lib/envoi/restore/agent.rb

Constant Summary collapse

DEFAULT_ASPERA_ARGS =
'-v -k3 --overwrite=diff -P 33001'
DEFAULT_DESTINATION_PATH =
'.'

Constants inherited from Mam::Agent

Mam::Agent::VERSION

Instance Attribute Summary collapse

Attributes inherited from Mam::Agent

#api_client, #config, #initial_args, #logger

Instance Method Summary collapse

Methods inherited from Mam::Agent

#dry_run?, #initialize, #initialize_api_client, #initialize_logger, load_config_and_init, load_config_from_file, load_config_from_service, load_from_config_file, load_from_config_service, #notify, #run_operation, #shell_execute

Constructor Details

This class inherits a constructor from Envoi::Mam::Agent

Instance Attribute Details

#default_aspera_ascp_argsObject

Returns the value of attribute default_aspera_ascp_args.



17
18
19
# File 'lib/envoi/restore/agent.rb', line 17

def default_aspera_ascp_args
  @default_aspera_ascp_args
end

#default_aspera_ascp_pathObject

Returns the value of attribute default_aspera_ascp_path.



17
18
19
# File 'lib/envoi/restore/agent.rb', line 17

def default_aspera_ascp_path
  @default_aspera_ascp_path
end

Instance Method Details

#after_initializeObject



20
21
22
23
24
25
26
27
28
# File 'lib/envoi/restore/agent.rb', line 20

def after_initialize
  args = initial_args
  @running = false
  @should_stop = false
  @default_aspera_ascp_path   = args[:default_aspera_ascp_path]
  @default_aspera_args = args[:default_ascp_args] || DEFAULT_ASPERA_ARGS
  initialize_queue_handler
  initialize_event_handler
end

#initialize_event_handlerObject



45
46
47
# File 'lib/envoi/restore/agent.rb', line 45

def initialize_event_handler
  @event_handler = GlacierRestoreEventHandler.new(config: sqs_config)
end

#initialize_queue_handlerObject



38
39
40
41
42
43
# File 'lib/envoi/restore/agent.rb', line 38

def initialize_queue_handler
  @queue_handler = SQSQueueWorker.new(config: sqs_config)
  @queue_handler.poller.before_request do |stats|
    throw :stop_polling if @should_stop
  end
end

#runObject



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/envoi/restore/agent.rb', line 49

def run
  @running = true
  @queue_handler.poll do |messages|
    [*messages].each do |msg|
      break if @should_stop
      msg_body_parsed = JSON.parse(msg.body)
      event = msg_body_parsed
      @event_handler.process_event(event)
    end
    throw :stop_polling if @should_stop
  end
  @running = false
end

#sqs_configObject



34
35
36
# File 'lib/envoi/restore/agent.rb', line 34

def sqs_config
  @sqs_config ||= system_config['sqs'] || {}
end

#stopObject



63
64
65
# File 'lib/envoi/restore/agent.rb', line 63

def stop
  @should_stop = true
end

#system_configObject



30
31
32
# File 'lib/envoi/restore/agent.rb', line 30

def system_config
  @system_config ||= config['restore'] || { }
end