Skip to content

Commit

Permalink
Merge pull request #1367 from sanger/fixes-for-volume-tracking-emq-in…
Browse files Browse the repository at this point in the history
…tegration

Updating to serialize UUIDs properly with raw UUID values
  • Loading branch information
dasunpubudumal authored Jul 24, 2024
2 parents 290447a + 14993a7 commit d85c3e7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 31 deletions.
4 changes: 3 additions & 1 deletion app/exchanges/volume_tracking/message_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def publish_data # rubocop:disable Metrics/MethodLength

aliquot = object
data = { source_type: '', source_barcode: '', sample_name: '',
used_by_type: 'nil', used_by_barcode: '', aliquot_uuid: aliquot.uuid || '' }
used_by_type: 'nil', used_by_barcode: '',
aliquot_uuid: aliquot.uuid,
message_uuid: SecureRandom.uuid }

case aliquot.source_type
when 'Pacbio::Library'
Expand Down
4 changes: 2 additions & 2 deletions config/pipelines/pacbio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ default: &default
type: :constant
value: Time.current
messageUuid:
type: :constant
value: SecureRandom.uuid.to_s
type: :self
value: publish_data&.message_uuid
recordedAt:
type: :model
value: created_at
Expand Down
48 changes: 24 additions & 24 deletions spec/exchanges/volume_tracking/message_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
let(:message_builder) { described_class.new(object: aliquot, configuration:) }

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

Expand All @@ -31,14 +31,14 @@
let(:message_builder) { described_class.new(object: aliquot, configuration:) }

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

Expand All @@ -47,14 +47,14 @@
let(:message_builder) { described_class.new(object: aliquot, configuration:) }

it 'produces the message in the correct format' do
expect(message_builder.publish_data).to eq({
source_type: 'library',
source_barcode: pacbio_library.tube.barcode,
sample_name: pacbio_library.sample_name,
used_by_type: 'well',
used_by_barcode: "#{pacbio_well.plate.sequencing_kit_box_barcode}:#{pacbio_well.plate.plate_number}:#{pacbio_well.position}",
aliquot_uuid: aliquot.uuid
})
expect(message_builder.publish_data).to include({
source_type: 'library',
source_barcode: pacbio_library.tube.barcode,
sample_name: pacbio_library.sample_name,
used_by_type: 'well',
used_by_barcode: "#{pacbio_well.plate.sequencing_kit_box_barcode}:#{pacbio_well.plate.plate_number}:#{pacbio_well.position}",
aliquot_uuid: aliquot.uuid
})
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/messages/emq/encoder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
RSpec.describe Emq::Encoder do
let(:pacbio_library) { create(:pacbio_library) }
let(:pacbio_pool) { create(:pacbio_pool) }
let(:aliquot) { build(:aliquot, source: pacbio_library, used_by: pacbio_pool, created_at: Time.zone.now) }
let(:aliquot) { build(:aliquot, uuid: SecureRandom.uuid, source: pacbio_library, used_by: pacbio_pool, created_at: Time.zone.now) }
let(:cache_file_path) { "data/avro_schema_cache/#{schema_subject}_v#{schema_version}.avsc" }
let(:schema_key) { 'volume_tracking' }
let(:schema_subject) { 'create-aliquot-in-mlwh' }
Expand Down
6 changes: 3 additions & 3 deletions spec/messages/emq/publishing_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
RSpec.describe Emq::PublishingJob do
let(:pacbio_library) { create(:pacbio_library) }
let(:pacbio_pool) { create(:pacbio_pool) }
let(:aliquot) { build(:aliquot, source: pacbio_library, used_by: pacbio_pool, created_at: Time.zone.now) }
let(:aliquot) { build(:aliquot, uuid: SecureRandom.uuid, source: pacbio_library, used_by: pacbio_pool, created_at: Time.zone.now) }

let(:publishing_job) { described_class.new }
let(:emq_sender_mock) { instance_double(Emq::Sender) }
Expand Down Expand Up @@ -73,13 +73,13 @@

it 'can publish multiple messages' do
expect(emq_sender_mock).to receive(:send_message).twice
aliquot2 = build(:aliquot, source: pacbio_library, used_by: pacbio_pool, created_at: Time.zone.now)
aliquot2 = build(:aliquot, uuid: SecureRandom.uuid, source: pacbio_library, used_by: pacbio_pool, created_at: Time.zone.now)
publishing_job.publish([aliquot, aliquot2], Pipelines.pacbio, 'volume_tracking')
end

it 'does not publish messages when schema key is missing in config' do
expect(emq_sender_mock).not_to receive(:send_message)
aliquot2 = build(:aliquot, source: pacbio_library, used_by: pacbio_pool, created_at: Time.zone.now)
aliquot2 = build(:aliquot, uuid: SecureRandom.uuid, source: pacbio_library, used_by: pacbio_pool, created_at: Time.zone.now)
publishing_job.publish([aliquot, aliquot2], Pipelines.pacbio, 'test')
end

Expand Down

0 comments on commit d85c3e7

Please sign in to comment.