-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving work reload_snapshot from the show to a background job (#1631)
This should allow the page to display for very large sets of files and the prvenance to be updated later Also putting this job on it's own queue since it could take a very long time we do not want it subverting other jobs refs #1621
- Loading branch information
1 parent
4978040
commit 1f52c04
Showing
5 changed files
with
64 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
class UpdateSnapshotJob < ApplicationJob | ||
queue_as :low | ||
|
||
def perform(work_id:, last_snapshot_id:) | ||
work = Work.find(work_id) | ||
|
||
# do nothing if there was another snapshot saved to the work between when this one was queued and when it started | ||
# Becuse this job can take so long lets not keep running it every time someone looks at the work | ||
# Unless this is a completely new visit after the last queued job completed | ||
return if work.upload_snapshots.first&.id != last_snapshot_id | ||
|
||
work.reload_snapshots | ||
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 |
---|---|---|
|
@@ -6,4 +6,5 @@ production: | |
:concurrency: 5 | ||
:queues: | ||
- default | ||
- low | ||
:max_retries: 25 |
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,36 @@ | ||
# frozen_string_literal: true | ||
require "rails_helper" | ||
|
||
RSpec.describe UpdateSnapshotJob, type: :job do | ||
include ActiveJob::TestHelper | ||
|
||
let(:user) { FactoryBot.create :user } | ||
|
||
let(:s3_file) { FactoryBot.build :s3_file, work:, filename: "#{work.prefix}/test_key" } | ||
|
||
describe "perform" do | ||
subject(:job) do | ||
described_class.perform_later(work_id: work.id, last_snapshot_id: nil) | ||
end | ||
let(:fake_s3_service) { stub_s3 prefix: "10.34770/ackh-7y71/#{work.id}", data: [s3_file] } | ||
let(:work) { FactoryBot.create :approved_work, doi: "10.34770/ackh-7y71" } | ||
|
||
before do | ||
fake_s3_service | ||
end | ||
|
||
it "creates an upload snapshot" do | ||
expect { perform_enqueued_jobs { job } }.to change { UploadSnapshot.count }.by(1) | ||
end | ||
|
||
context "when last snapshot is different" do | ||
subject(:job) do | ||
described_class.perform_later(work_id: work.id, last_snapshot_id: 123) | ||
end | ||
|
||
it "skips processing" do | ||
expect { perform_enqueued_jobs { job } }.to change { UploadSnapshot.count }.by(0) | ||
end | ||
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