Class: GenerateArksRunner

Inherits:
JobRunner show all
Defined in:
backend/app/lib/job_runners/generate_arks_runner.rb

Instance Method Summary collapse

Methods inherited from JobRunner

#add_success_hook, #cancelation_signaler, #canceled?, for, #initialize, #parse_job_params_string, register_for_job_type, registered_job_types, registered_runner_for, #success!, #symbol_keys

Constructor Details

This class inherits a constructor from JobRunner

Instance Method Details

#runObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'backend/app/lib/job_runners/generate_arks_runner.rb', line 6

def run
  begin
    # RESOURCES
    @job.write_output("Generating ARKs for Resources")
    @job.write_output("================================")

    count_res = 0
    Resource.any_repo.each do |r|
      begin
        if ArkName.count == 0 || ArkName.first(resource_id: r[:id]).nil?
          @job.write_output("Generating ARK for resource id: #{r[:id]}")
          ArkName.insert(:archival_object_id => nil,
                         :resource_id        => r[:id],
                         :created_by         => 'admin',
                         :last_modified_by   => 'admin',
                         :create_time        => Time.now,
                         :system_mtime       => Time.now,
                         :user_mtime         => Time.now,
                         :lock_version       => 0)
          count_res += 1
        end
      rescue => e
        @job.write_output(" -> Error generating ARK for id: #{r[:id]} => #{e.message}")
      end
    end

    if count_res == 0
      @job.write_output("No Resource ARKs were generated because all Resource records already have ARKs")
      @job.write_output("================================")
    end

    # Archival Object
    @job.write_output("Generating ARKs for Archival Objects")
    @job.write_output("================================")

    count_aos = 0
    ArchivalObject.any_repo.each do |r|
      begin
        if ArkName.count == 0 || ArkName.first(archival_object_id: r[:id]).nil?
          @job.write_output("Generating ARK for Archival Object id: #{r[:id]}")
          ArkName.insert(:archival_object_id => r[:id],
                         :resource_id        => nil,
                         :created_by         => 'admin',
                         :last_modified_by   => 'admin',
                         :create_time        => Time.now,
                         :system_mtime       => Time.now,
                         :user_mtime         => Time.now,
                         :lock_version       => 0)
          count_aos += 1
        end
      rescue => e
        @job.write_output(" -> Error generating ARK for id: #{r[:id]} => #{e.message}")
      end
    end

    if count_aos == 0
      @job.write_output("No Archival Object ARKs were generated because all Archival Object records already have ARKs")
      @job.write_output("================================")
    end

    self.success!
  rescue Exception => e
    @job.write_output(e.message)
    @job.write_output(e.backtrace)
    raise e
  end
end