Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion app/jobs/update_digital_objects_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class UpdateDigitalObjectsJob < ApplicationJob
queue_as :metadata
VOYAGER_AUTHORITATIVE_SOURCE_ID = 2

def self.job_limit
5000
Expand All @@ -10,7 +11,9 @@ def self.job_limit
# rubocop:disable Style/OptionalArguments
# rubocop:disable Lint/UselessAssignment
def perform(admin_set_id, start_position = 0)
parent_objects = ParentObject.where(admin_set_id: admin_set_id).order(:oid).offset(start_position).limit(UpdateDigitalObjectsJob.job_limit)
parent_objects = ParentObject.where(admin_set_id: admin_set_id, authoritative_metadata_source_id: VOYAGER_AUTHORITATIVE_SOURCE_ID)
.order(:oid).offset(start_position)
.limit(UpdateDigitalObjectsJob.job_limit)
last_job = parent_objects.count < UpdateDigitalObjectsJob.job_limit
return unless parent_objects.count.positive? # stop if nothing is found
parent_objects.each do |po|
Expand All @@ -22,3 +25,10 @@ def perform(admin_set_id, start_position = 0)
# rubocop:enable Style/OptionalArguments
# rubocop:enable Lint/UselessAssignment
end

def push_pos(parent_objects)
parent_objects.each do |po|
# only force digital_object_check if a solr document is generated, or if it's private
po.digital_object_check(true) if po.to_solr.present? && po.child_object_count&.positive? && po.ready_for_manifest?
end
end
12 changes: 6 additions & 6 deletions spec/jobs/update_digital_objects_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'rails_helper'

RSpec.describe UpdateDigitalObjectsJob, type: :job, prep_metadata_sources: true, solr: true do
let(:parent_object) { FactoryBot.build(:parent_object, oid: '16797069') }
let(:parent_object) { FactoryBot.build(:parent_object, oid: '16797069', authoritative_metadata_source_id: 2) }
let(:admin_set_1) { FactoryBot.create(:admin_set) }

context 'with tests active job queue' do
Expand Down Expand Up @@ -38,7 +38,7 @@ def queue_adapter_for_test
end

context 'without digital object json' do
let(:po1) { FactoryBot.create(:parent_object, oid: '000000001', admin_set_id: admin_set_1.id) }
let(:po1) { FactoryBot.create(:parent_object, oid: '000000001', admin_set_id: admin_set_1.id, authoritative_metadata_source_id: 2) }
before do
allow(UpdateDigitalObjectsJob).to receive(:job_limit).and_return(2)
allow(SetupMetadataJob).to receive(:perform_later) # this is just to prevent errors trying to get metadata
Expand All @@ -50,7 +50,7 @@ def queue_adapter_for_test
end
end
context 'with digital object json' do
let(:po1) { FactoryBot.create(:parent_object, oid: '000000001', admin_set_id: admin_set_1.id) }
let(:po1) { FactoryBot.create(:parent_object, oid: '000000001', admin_set_id: admin_set_1.id, authoritative_metadata_source_id: 2) }
let(:digital_object_json1) { FactoryBot.create(:digital_object_json, parent_object: po1) }
before do
allow(UpdateDigitalObjectsJob).to receive(:job_limit).and_return(2)
Expand All @@ -68,9 +68,9 @@ def queue_adapter_for_test
end

context 'with more than limit parent objects' do
let(:po1) { FactoryBot.create(:parent_object, oid: '000000001', admin_set_id: admin_set_1.id) }
let(:po2) { FactoryBot.create(:parent_object, oid: '000000002', admin_set_id: admin_set_1.id) }
let(:po3) { FactoryBot.create(:parent_object, oid: '000000003', admin_set_id: admin_set_1.id) }
let(:po1) { FactoryBot.create(:parent_object, oid: '000000001', admin_set_id: admin_set_1.id, authoritative_metadata_source_id: 2) }
let(:po2) { FactoryBot.create(:parent_object, oid: '000000002', admin_set_id: admin_set_1.id, authoritative_metadata_source_id: 2) }
let(:po3) { FactoryBot.create(:parent_object, oid: '000000003', admin_set_id: admin_set_1.id, authoritative_metadata_source_id: 2) }
let(:digital_object_json1) { FactoryBot.create(:digital_object_json, parent_object: po1) }
let(:digital_object_json2) { FactoryBot.create(:digital_object_json, parent_object: po2) }
let(:digital_object_json3) { FactoryBot.create(:digital_object_json, parent_object: po3) }
Expand Down