Class: Itchy::MetadataArchiver

Inherits:
Object
  • Object
show all
Defined in:
lib/itchy/metadata_archiver.rb

Overview

Wraps vmcatcher event handling methods. All events are stored for subsequent processing. There is no actual image handling happening here.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vmc_configuration, options) ⇒ MetadataArchiver

Creates an archiver instance for storing vmcatcher events to the file system for delayed processing.

Parameters:



13
14
15
16
17
18
19
20
21
# File 'lib/itchy/metadata_archiver.rb', line 13

def initialize(vmc_configuration, options)
  fail ArgumentError, '"vmc_configuration" must be an instance ' \
       'of Itchy::VmcatcherConfiguration' unless vmc_configuration.is_a? Itchy::VmcatcherConfiguration

  @vmc_configuration = vmc_configuration
  @options = options || ::Hashie::Mash.new

  
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/itchy/metadata_archiver.rb', line 6

def options
  @options
end

#vmc_configurationObject (readonly)

Returns the value of attribute vmc_configuration.



6
7
8
# File 'lib/itchy/metadata_archiver.rb', line 6

def vmc_configuration
  @vmc_configuration
end

Instance Method Details

#archive!(vmc_event) ⇒ Object

Triggers archiving of the provided event. Event is written to the file system as a JSON-formatted document for delayed processing.

Parameters:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/itchy/metadata_archiver.rb', line 28

def archive!(vmc_event)
  fail ArgumentError, '"vmc_event" must be an instance ' \
       'of Itchy::VmcatcherEvent' unless vmc_event.is_a? Itchy::VmcatcherEvent

  Itchy::Log.info "[#{self.class.name}] Archiving " \
                         "#{vmc_event.type.inspect} " \
                         "for #{vmc_event.dc_identifier.inspect}"

  begin
    event_handler = Itchy::EventHandlers.const_get("#{vmc_event.type}EventHandler")
  rescue NameError => ex
    fail Itchy::Errors::UnknownEventError,
          "Unknown event type #{vmc_event.type.inspect} detected: #{ex.message}"
  end

  event_handler = event_handler.new(vmc_configuration, options)
  event_handler.archive!(vmc_event)
end