Skip to content

Commit

Permalink
Enqueue SampleTypeUpdateJob after performing UpdateSampleMetadataJob
Browse files Browse the repository at this point in the history
  • Loading branch information
kdp-cloud committed Nov 13, 2024
1 parent 48e94de commit 5d5ae6b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 4 additions & 0 deletions app/jobs/update_sample_metadata_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ class UpdateSampleMetadataJob < TaskJob
queue_with_priority 1
queue_as QueueNames::SAMPLES

after_perform do |job|
SampleTypeUpdateJob.perform_later(job.arguments.first, true)
end

def perform(sample_type, user, attribute_changes = [])
@sample_type = sample_type
@user = user
Expand Down
16 changes: 8 additions & 8 deletions test/unit/jobs/update_sample_metadata_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@ def setup
(1..10).each do |_i|
FactoryBot.create(:sample, sample_type: @sample_type, contributor: @person)
end
Rails.cache.clear
end

def teardown
Rails.cache.clear
end

test 'perform' do
User.with_current_user(@person.user) do
UpdateSampleMetadataJob.perform_now(@sample_type, @person.user, [])
assert_enqueued_with(job: SampleTypeUpdateJob, args: [@sample_type, true])
end
end

Expand Down Expand Up @@ -58,6 +54,9 @@ def teardown
end

test 'perform with unexpected error' do
# Clears the queue of all jobs
# Queue has already multiple SampleTypeUpdateJob jobs from the setup
clear_enqueued_jobs
job = UpdateSampleMetadataJob.new(@sample_type, @person.user, 'bad_attribute_change_map')
assert_enqueued_with(job: UpdateSampleMetadataJob, args: [@sample_type, @person.user, 'bad_attribute_change_map']) do
job.enqueue
Expand All @@ -66,9 +65,10 @@ def teardown

perform_enqueued_jobs do
job.perform_now
rescue StandardError
# The sample type should be unlocked even if an error occurs
refute @sample_type.locked?
end
# The sample type should be unlocked even if an error occurs
refute @sample_type.locked?
# SampleTypeUpdateJob should not be enqueued when an error occurs
assert_no_enqueued_jobs only: SampleTypeUpdateJob
end
end

0 comments on commit 5d5ae6b

Please sign in to comment.