Skip to content

Commit

Permalink
Capture the ActiveRecord timeout and retry (#1926)
Browse files Browse the repository at this point in the history
  • Loading branch information
carolyncole authored Sep 13, 2024
1 parent e32700c commit 8cc42bb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/jobs/dspace_file_copy_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@ def update_migration(migration_snapshot_id, s3_key, s3_size, work)
migration_snapshot.mark_complete(S3File.new(filename: s3_key, last_modified: DateTime.now, size: s3_size, checksum: "", work:))
migration_snapshot.save!
end

rescue ActiveRecord::StatementInvalid
ActiveRecord::Base.connection_pool.release_connection
retry
end
end
23 changes: 23 additions & 0 deletions spec/jobs/dspace_file_copy_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@
target_bucket: "work-bucket", target_key: "abc/123/#{work.id}/test_key")
end

context "when an ActiveRecord::StatementInvalid error occurs" do
before do
@error_count = 0
allow(MigrationUploadSnapshot).to receive(:find) do
if @error_count == 0
@error_count = 1
raise ActiveRecord::StatementInvalid, "error"
else
migration_snapshot
end
end
end

it "runs the copy and updates the snapshot" do
allow(migration_snapshot).to receive(:"save!").and_call_original
perform_enqueued_jobs { job }
expect(fake_s3_service).to have_received(:copy_file).with(size: 10_759, source_key: "example-bucket-dspace/10-34770/ackh-7y71/test_key",
target_bucket: "work-bucket", target_key: "abc/123/#{work.id}/test_key")

expect(migration_snapshot).to have_received(:"save!")
end
end

context "when the files is a directory" do
let(:s3_file) { FactoryBot.build :s3_file, filename: "10-34770/ackh-7y71/dir/", size: 0, filename_display: "abc/123/#{work.id}/dir/" }

Expand Down

0 comments on commit 8cc42bb

Please sign in to comment.