-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Segment Large CSV Batch Processes (#1475)
* segment delete parent job * Add start of test * reassociate child oids segmented * segment recreate child ptiff * segment update parent objects job * rubocop and spec * remove comments * Update variable naming * Update numbers * skip already processed rows * rubocop * alter job limit in specs * Update variable name * Extend expectation * Add expectations * adds skipped row expectations to spec * save delete batch process * add comment back * Add additional test * confirm hitting perform_later twice * Add test * Refactor variable * fix spec * reassociate spec csv and expectations * Add fixture * Update stubbing and expectations * Update to use variable * Use variable instead and clean up * adds row skipping to already processed rows * Change access mount * Implement segment on create parent and clean up * make spec more resilient * Add guards * Add return and cleanup * more cleaning --------- Co-authored-by: JP Engstrom <[email protected]> Co-authored-by: K8Sewell <[email protected]> Co-authored-by: JP Engstrom <[email protected]>
- Loading branch information
1 parent
d07251d
commit 2a311eb
Showing
19 changed files
with
311 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
oid,source,admin_set | ||
2005512,ladybird,brbl | ||
2005513,ladybird,brbl | ||
2005514,ladybird,brbl | ||
2005515,ladybird,brbl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
oid,action,source,admin_set | ||
2005512,delete,ladybird,brbl | ||
2005513,delete,ladybird,brbl | ||
2005514,delete,ladybird,brbl | ||
2005515,delete,ladybird,brbl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
child_oid,parent_oid,order,parent_title,label,caption,viewing_hint | ||
1030368,2005515,,,,, | ||
1032318,2005514,,,,, | ||
1030368,2002826,,,,, | ||
1032318,2002826,,,,, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe CreateNewParentJob, type: :job, prep_metadata_sources: true, prep_admin_sets: true do | ||
let(:admin_set) { AdminSet.find_by(key: 'brbl') } | ||
let(:user) { FactoryBot.create(:user) } | ||
let(:create_many) { Rack::Test::UploadedFile.new(Rails.root.join(fixture_path, "csv", "create_many_parent_fixture_ids.csv")) } | ||
let(:create_batch_process) { FactoryBot.create(:batch_process, user: user, file: create_many) } | ||
let(:bare_create_batch_process) { FactoryBot.create(:batch_process, user: user) } | ||
let(:total_parent_object_count) { 4 } | ||
|
||
before do | ||
allow(GoodJob).to receive(:preserve_job_records).and_return(true) | ||
ActiveJob::Base.queue_adapter = GoodJob::Adapter.new(execution_mode: :inline) | ||
end | ||
|
||
it 'increments the job queue by one' do | ||
create_parent_job = described_class.perform_later(bare_create_batch_process) | ||
expect(create_parent_job.instance_variable_get(:@successfully_enqueued)).to eq true | ||
end | ||
|
||
context 'with more than limit of batch objects' do | ||
before do | ||
BatchProcess::BATCH_LIMIT = 2 | ||
expect(ParentObject.all.count).to eq 0 | ||
user.add_role(:editor, admin_set) | ||
login_as(:user) | ||
expect(described_class).to receive(:perform_later).exactly(2).times.and_call_original | ||
end | ||
|
||
around do |example| | ||
perform_enqueued_jobs do | ||
example.run | ||
end | ||
end | ||
|
||
it 'goes through all parents in batches once' do | ||
create_batch_process.save | ||
expect(ParentObject.all.count).to eq total_parent_object_count | ||
expect(IngestEvent.where(reason: 'Processing has been queued').count).to eq total_parent_object_count | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe DeleteParentObjectsJob, type: :job, prep_metadata_sources: true, prep_admin_sets: true do | ||
let(:admin_set) { AdminSet.find_by(key: 'brbl') } | ||
let(:user) { FactoryBot.create(:user) } | ||
let(:create_many) { Rack::Test::UploadedFile.new(Rails.root.join(fixture_path, "csv", "create_many_parent_fixture_ids.csv")) } | ||
let(:delete_many) { Rack::Test::UploadedFile.new(Rails.root.join(fixture_path, "csv", "delete_many_parent_fixture_ids.csv")) } | ||
let(:create_batch_process) { FactoryBot.create(:batch_process, user: user, file: create_many) } | ||
let(:delete_batch_process) { FactoryBot.create(:batch_process, user: user, file: delete_many, batch_action: 'delete parent objects') } | ||
|
||
before do | ||
allow(GoodJob).to receive(:preserve_job_records).and_return(true) | ||
ActiveJob::Base.queue_adapter = GoodJob::Adapter.new(execution_mode: :inline) | ||
end | ||
|
||
context 'with tests active job queue' do | ||
it 'increments the job queue by one' do | ||
delete_parent_job = described_class.perform_later | ||
expect(delete_parent_job.instance_variable_get(:@successfully_enqueued)).to be true | ||
end | ||
end | ||
|
||
context 'with more than limit parent objects' do | ||
before do | ||
BatchProcess::BATCH_LIMIT = 2 | ||
expect(ParentObject.all.count).to eq 0 | ||
user.add_role(:editor, admin_set) | ||
login_as(:user) | ||
create_batch_process.save | ||
total_parent_object_count = 4 | ||
expect(ParentObject.all.count).to eq total_parent_object_count | ||
expect(described_class).to receive(:perform_later).exactly(2).times.and_call_original | ||
end | ||
|
||
around do |example| | ||
perform_enqueued_jobs do | ||
example.run | ||
end | ||
end | ||
|
||
it 'goes through all parents in batches once' do | ||
delete_batch_process.save | ||
expect(IngestEvent.where(status: 'deleted').and(IngestEvent.where(reason: 'Parent 2005512 has been deleted')).count).to eq 1 | ||
expect(IngestEvent.where(status: 'Skipped Row').and(IngestEvent.where(reason: 'Skipping row [2] with parent oid: 2005512 because it was not found in local database')).count).to eq 0 | ||
expect(IngestEvent.where(status: 'deleted').and(IngestEvent.where(reason: 'Parent 2005513 has been deleted')).count).to eq 1 | ||
expect(IngestEvent.where(status: 'Skipped Row').and(IngestEvent.where(reason: 'Skipping row [3] with parent oid: 2005513 because it was not found in local database')).count).to eq 0 | ||
expect(IngestEvent.where(status: 'deleted').and(IngestEvent.where(reason: 'Parent 2005514 has been deleted')).count).to eq 1 | ||
expect(IngestEvent.where(status: 'deleted').and(IngestEvent.where(reason: 'Parent 2005515 has been deleted')).count).to eq 1 | ||
expect(ParentObject.all.count).to eq 0 | ||
end | ||
end | ||
end |
Oops, something went wrong.