Class: Hyrax::Ingest::BatchRunner

Inherits:
Object
  • Object
show all
Includes:
HasDepositor, HasLogger, HasReport, Interloper
Defined in:
lib/hyrax/ingest/batch_runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HasDepositor

included

Methods included from HasLogger

config, #logger, #logger=

Methods included from HasReport

#report, #report=

Constructor Details

#initialize(config_file_path:, sip_paths: [], shared_sip_path: nil, iterations: nil, depositor: nil) ⇒ BatchRunner

Returns a new instance of BatchRunner.



30
31
32
33
34
35
36
# File 'lib/hyrax/ingest/batch_runner.rb', line 30

def initialize(config_file_path:, sip_paths: [], shared_sip_path: nil, iterations: nil, depositor: nil)
  @sip_paths = sip_paths
  @shared_sip_path = shared_sip_path
  @config_file_path = config_file_path
  @iterations = iterations
  self.depositor = depositor
end

Instance Attribute Details

#sip_pathsObject (readonly)

Returns the value of attribute sip_paths.



28
29
30
# File 'lib/hyrax/ingest/batch_runner.rb', line 28

def sip_paths
  @sip_paths
end

Instance Method Details

#ingested_idsArray

Returns an array containing the IDs of new or updated records. Currently only returns the IDs for ActiveFedora records (or subclasses) that are specified at the top level (i.e. not nested) of the ingest configuration.

Returns:

  • (Array)

    list of IDs



57
58
59
# File 'lib/hyrax/ingest/batch_runner.rb', line 57

def ingested_ids
  ingested_ids_by_type.flatten
end

#ingested_ids_by_typeHash

Returns an hash containing the IDs of new or updated records, keyed by the model class by which they were saved. Example:

{ FileSet => ['123', '456'], Work => ['789'] }

Currently only returns the IDs for ActiveFedora records (or subclasses) that are specified at the top level (i.e. not nested) of the ingest configuration.

Returns:

  • (Hash)

    IDs keyed by the model class by which they were saved.



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/hyrax/ingest/batch_runner.rb', line 69

def ingested_ids_by_type
  {}.tap do |h|
    runners.each do |runner|
      runner.ingested_ids_by_type.each do |type, ids|
        h[type] ||= []
        h[type] += ids
        h[type].uniq!
      end
    end
  end
end

#run!Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/hyrax/ingest/batch_runner.rb', line 38

def run!
  runners.each { |runner| runner.run! }
rescue StandardError => error
  # TODO: move to callback, but :rescue hook doesn't exist yet in
  # Interloper gem.
  report.stat[:datetime_completed] = DateTime.now
  report.failed_with error
  raise error
ensure
  # TODO: move to callback, but :ensure hook doesn't exist yet in
  # Interloper gem.
  report.write_to_file
end