Class: Robots::SdrRepo::SdrIngest::IngestCleanup

Inherits:
Robots::SdrRepo::SdrRobot show all
Defined in:
lib/sdr_ingest/ingest_cleanup.rb

Overview

Robot for completing the processing of each ingested object

Instance Method Summary collapse

Methods inherited from Robots::SdrRepo::SdrRobot

#create_workflow_rows, #get_workflow_status, #get_workflow_xml, #process_item, #transmit, #update_workflow_error_status, #update_workflow_status

Constructor Details

#initialize(opts = {}) ⇒ IngestCleanup

set workflow name, step name, log location, log severity level


16
17
18
# File 'lib/sdr_ingest/ingest_cleanup.rb', line 16

def initialize(opts = {})
  super(self.class.workflow_name, self.class.step_name, opts)
end

Instance Method Details

#cleanup_deposit_files(druid, bag_pathname) ⇒ Boolean


40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/sdr_ingest/ingest_cleanup.rb', line 40

def cleanup_deposit_files(druid, bag_pathname)
  # retry up to 3 times
  sleep_time = [0, 2, 6]
  attempts ||= 0
  bag_pathname.rmtree
  return true
rescue StandardError => e
  if (attempts += 1) < sleep_time.size
    sleep sleep_time[attempts].to_i
    retry
  else
    raise ItemError.new("Failed cleanup deposit (#{attempts} attempts)")
  end
end

#ingest_cleanup(druid, bag_pathname) ⇒ void


32
33
34
35
# File 'lib/sdr_ingest/ingest_cleanup.rb', line 32

def ingest_cleanup(druid, bag_pathname)
  cleanup_deposit_files(druid, bag_pathname) if bag_pathname.exist?
  update_workflow_status('dor', druid, 'accessionWF', 'sdr-ingest-received', 'completed', 1)
end

#perform(druid) ⇒ void


23
24
25
26
27
# File 'lib/sdr_ingest/ingest_cleanup.rb', line 23

def perform(druid)
  LyberCore::Log.debug("( #{__FILE__} : #{__LINE__} ) Enter perform")
  bag_pathname = Replication::SdrObject.new(druid).deposit_bag_pathname
  ingest_cleanup(druid, bag_pathname)
end

#verification_files(druid) ⇒ Object


64
65
66
67
68
# File 'lib/sdr_ingest/ingest_cleanup.rb', line 64

def verification_files(druid)
  files = []
  files << Moab::StorageServices.object_path(druid).to_s
  files
end

#verification_queries(druid) ⇒ Object


55
56
57
58
59
60
61
62
# File 'lib/sdr_ingest/ingest_cleanup.rb', line 55

def verification_queries(druid)
  workflow_url = Dor::Config.workflow.url
  queries = []
  queries << [
      "#{workflow_url}/sdr/objects/#{druid}/workflows/sdrIngestWF",
      200, /completed/]
  queries
end