Skip to content

Commit

Permalink
Merge pull request #1455 from sanger/1451-y24-370---as-tree-of-life-w…
Browse files Browse the repository at this point in the history
…e-would-like-the-sample-data-in-the-warehouse-when-a-library-is-created-so-that-we-can-track-back-to-the-original-plate-or-tube-barcode-to-make-the-top-up-process-more-efficient

Publishing filtered aliquots
  • Loading branch information
dasunpubudumal authored Oct 22, 2024
2 parents bc3b5a4 + d6f8e0c commit b8ed416
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
9 changes: 9 additions & 0 deletions app/exchanges/volume_tracking/message_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def base_data
}
end

# rubocop:disable Metrics/MethodLength
def populate_by_source_type(data)
case object.source_type
when 'Pacbio::Library'
Expand All @@ -56,8 +57,13 @@ def populate_by_source_type(data)
data[:source_type] = 'pool'
data[:source_barcode] = object.source.tube.barcode
data[:sample_name] = pacbio_library_sample_names
when 'Pacbio::Request'
data[:source_type] = 'request'
data[:source_barcode] = object.source.container.barcode
data[:sample_name] = object.source.sample_name
end
end
# rubocop:enable Metrics/MethodLength

def populate_by_used_type(data)
case object.used_by_type
Expand All @@ -67,6 +73,9 @@ def populate_by_used_type(data)
when 'Pacbio::Pool'
data[:used_by_type] = 'pool'
data[:used_by_barcode] = object.used_by.tube.barcode
when 'Pacbio::Library'
data[:used_by_type] = 'library'
data[:used_by_barcode] = object.used_by.tube.barcode
end
end

Expand Down
9 changes: 5 additions & 4 deletions app/resources/v1/pacbio/library_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def self.default_sort
# to republish the messages for the run
after_update :publish_messages

after_create :publish_volume_tracking_message
after_create :publish_volume_tracking_messages

filter :sample_name, apply: lambda { |records, value, _options|
# We have to join requests and samples here in order to find by sample name
Expand Down Expand Up @@ -130,11 +130,12 @@ def deactivated_at

def publish_messages
Messages.publish(@model.sequencing_runs, Pipelines.pacbio.message)
publish_volume_tracking_message
publish_volume_tracking_messages
end

def publish_volume_tracking_message
Emq::Publisher.publish(@model.primary_aliquot, Pipelines.pacbio, 'volume_tracking')
def publish_volume_tracking_messages
Emq::Publisher.publish([@model.primary_aliquot, *@model.used_aliquots],
Pipelines.pacbio, 'volume_tracking')
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion config/pipelines/pacbio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ default: &default
# The number suffix '1' is used to identify the schema version of message (created by the
# message builder class defined in the message_class key)
# The schema version number should be present in bunny.yml for the same 'key'
avro_schema_version_1 :
avro_schema_version_1: &avro_schema_version_1
lims: Traction
key: 'volume_tracking'
message_class: VolumeTracking::MessageBuilder
Expand Down Expand Up @@ -351,6 +351,8 @@ default: &default
usedByType:
type: :self
value: publish_data&.used_by_type
avro_schema_version_2:
<<: *avro_schema_version_1
development: *default
test: *default
uat: *default
Expand Down
18 changes: 18 additions & 0 deletions spec/exchanges/volume_tracking/message_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,24 @@
end
end

context 'with an aliquot with request as source and library as used_by' do
let(:configuration) { Pipelines.pacbio.volume_tracking.avro_schema_version_2 }
let(:aliquot) { create(:aliquot, source: pacbio_request, used_by: pacbio_library) }
let(:message_builder) { described_class.new(object: aliquot, configuration:) }
let(:pacbio_request) { create(:pacbio_request, tube: create(:tube, barcode: '123456789')) }

it 'produces the message in the correct format' do
expect(message_builder.publish_data).to include({
source_type: 'request',
source_barcode: pacbio_request.tube.barcode,
sample_name: pacbio_request.sample_name,
used_by_type: 'library',
used_by_barcode: pacbio_library.tube.barcode,
aliquot_uuid: aliquot.uuid
})
end
end

context 'with a aliquot with library as source and pool as used_by' do
let(:aliquot) { create(:aliquot, source: pacbio_library, used_by: pacbio_pool) }
let(:message_builder) { described_class.new(object: aliquot, configuration:) }
Expand Down
10 changes: 5 additions & 5 deletions spec/messages/emq/publishing_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
subjects: {
volume_tracking: {
subject: 'create-aliquot-in-mlwh',
version: 1
version: 2
}
}
}
Expand All @@ -48,7 +48,7 @@
let(:bunny_config_obj) { described_class.deep_open_struct(bunny_config) }

let(:subject_obj) { 'create-aliquot-in-mlwh' }
let(:version_obj) { 1 }
let(:version_obj) { 2 }

let(:volume_tracking_avro_response) do
allow(Rails.configuration).to receive(:bunny).and_return(bunny_config)
Expand Down Expand Up @@ -86,9 +86,9 @@
end

it 'logs an error when the message building config misses the given avro schema version' do
bunny_config[:amqp][:schemas][:subjects][:volume_tracking][:version] = 2
bunny_config[:amqp][:schemas][:subjects][:volume_tracking][:version] = 3
expect(emq_sender_mock).not_to receive(:send_message)
expect(Rails.logger).to receive(:error).with('Message builder configuration not found for schema key: volume_tracking and version: 2')
expect(Rails.logger).to receive(:error).with('Message builder configuration not found for schema key: volume_tracking and version: 3')
publishing_job.publish(aliquot, Pipelines.pacbio, 'volume_tracking')
end

Expand All @@ -102,7 +102,7 @@
assert_equal 'traction', deep_struct.amqp.isg.exchange
assert_equal 'http://test-redpanda/subjects/', deep_struct.amqp.schemas.registry_url
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
assert_equal 2, deep_struct.amqp.schemas.subjects.volume_tracking.version
end

it 'logs error message when the EMQ is down' do
Expand Down

0 comments on commit b8ed416

Please sign in to comment.