Skip to content

Commit

Permalink
Merge pull request #1431 from sanger/1427-y24-306---bug-as-developers…
Browse files Browse the repository at this point in the history
…-we-need-to-modify-the-emq-publishing-job-so-it-doesnt-raise-an-error-as-this-stops-users-being-able-to-create-libraries-pools-or-runs-if-the-queue-is-down

Updating the code to not to throw when the EMQ is down
  • Loading branch information
dasunpubudumal authored Sep 17, 2024
2 parents 0c89312 + 68c9bc6 commit 04c4550
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/messages/emq/publishing_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ def publish(objects, message_config, schema_key) # rubocop:disable Metrics/AbcSi
# Log success message after successful publishing
Rails.logger.info('Published volume tracking message to EMQ')
rescue StandardError => e
# Raise an exception if any error occurs
raise "Failed to publish message to EMQ: #{e.message}"
# DO NOT Raise an exception if any error occurs; logs the error instead
# This is to prevent the job from failing and to allow the job to continue
# These logs can be monitored through Kibana
Rails.logger.error("Failed to publish message to EMQ: #{e.message}")
end
end

Expand Down
6 changes: 6 additions & 0 deletions spec/messages/emq/publishing_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,10 @@
assert_equal 'create-aliquot-in-mlwh', deep_struct.amqp.schemas.subjects.volume_tracking.subject
assert_equal 1, deep_struct.amqp.schemas.subjects.volume_tracking.version
end

it 'logs error message when the EMQ is down' do
allow(emq_sender_mock).to receive(:send_message).and_raise(StandardError)
expect(Rails.logger).to receive(:error).with('Failed to publish message to EMQ: StandardError')
publishing_job.publish(aliquot, Pipelines.pacbio, 'volume_tracking')
end
end

0 comments on commit 04c4550

Please sign in to comment.