Skip to content

Commit

Permalink
Handle unknown subjects in the retirement worker (#3651)
Browse files Browse the repository at this point in the history
* ignore unknown subjects

don't fail on a subject id that doesn't resolve to a subject - instead rescue and keep processing the list we have for retirement

* remove redundant specs

these tested the error condition we now rescue and ignore
  • Loading branch information
camallen authored Sep 7, 2021
1 parent 85af7c8 commit ab63cb6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
3 changes: 3 additions & 0 deletions app/workers/retire_subject_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ def perform(workflow_id, subject_ids, reason=nil)
Array.wrap(subject_ids).each do |subject_id|
count = subject_workflow_status(subject_id)
RetirementWorker.perform_async(count.id, true, reason)
rescue ActiveRecord::RecordInvalid
# need to rescue the error when folks pass in a subject id that doesn't exist
# but we still keep processing the whole list of subjects we have
end
end
end
Expand Down
24 changes: 7 additions & 17 deletions spec/workers/retire_subject_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@
let(:subject_ids) { [sms.subject_id, sms2.subject_id] }

describe "#perform" do
it 'should handle an unknow workflow' do
it 'ignores an unknown workflow' do
expect { worker.perform(-1, subject.id) }.not_to raise_error
end

it 'ignores an unknown subject' do
allow(RetirementWorker).to receive(:perform_async)
worker.perform(workflow.id, [-1, subject.id])
expect(RetirementWorker).to have_received(:perform_async).once
end

it 'should call the retirement worker with the subject workflow status resource' do
expect(RetirementWorker)
.to receive(:perform_async)
Expand All @@ -41,21 +47,5 @@
expect(RetirementWorker).not_to receive(:perform_async)
worker.perform(-1, subject.id)
end

describe "creating the sws resource" do
it 'should raise if there is a problem with the workflow' do
allow(worker).to receive(:workflow_exists?).and_return(true)
expect {
worker.perform(-1, subject.id)
}.to raise_error(ActiveRecord::RecordInvalid)
end

it 'should raise if there is a problem with the subject' do
allow(worker).to receive(:workflow_exists?).and_return(true)
expect {
worker.perform(workflow.id, -1)
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
end
end

0 comments on commit ab63cb6

Please sign in to comment.