From db8519157b6a74bfb6bd44e455ffa724c8ed7d2d Mon Sep 17 00:00:00 2001 From: Andrew Sparkes Date: Fri, 17 Jul 2020 14:43:56 +0100 Subject: [PATCH] Removed API call to lighthouse on receiving plates. Lighthouse plates are now received into Sequencescape via a different process. --- README.md | 2 - app/controllers/process_plates_controller.rb | 18 ++---- config/environments/development.rb | 3 - config/environments/test.rb | 3 - lib/lighthouse.rb | 40 ------------- test/controllers/process_plates_controller.rb | 28 ++------- test/unit/lighthouse_test.rb | 58 ------------------- 7 files changed, 9 insertions(+), 143 deletions(-) delete mode 100644 lib/lighthouse.rb delete mode 100644 test/unit/lighthouse_test.rb diff --git a/README.md b/README.md index 2d1c9869..7a56e4ce 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,6 @@ Sequencescape. * [Sequencescape](https://github.com/sanger/sequencescape/) is required to authenticate against * [wrangler](https://github.com/sanger/wrangler/) is required if you want automatic sample creation in Sequencescape when tube racks are scanned in -* [lighthouse](https://github.com/sanger/lighthouse) is required for automatic sample creation in -Sequencescape for plates received from the Lighthouse Labs ## Getting started diff --git a/app/controllers/process_plates_controller.rb b/app/controllers/process_plates_controller.rb index 8ca1d01c..bae1d9d1 100644 --- a/app/controllers/process_plates_controller.rb +++ b/app/controllers/process_plates_controller.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true class ProcessPlatesController < ApplicationController require 'wrangler' - require 'lighthouse' skip_before_action :configure_api, except: [:create] @@ -61,17 +60,12 @@ def receive_plates_process?(params) @receive_plates_process ||= InstrumentProcess.find_by(id: params[:instrument_process]).key.eql?('slf_receive_plates') end - # Call any external services - currently lighthouse service for plates from Lighthouse Labs and - # wrangler for tube racks. If no samples are found in the lighthouse service, try the wrangler + # Call any external services - currently wrangler for tube racks. def call_external_services(barcodes) - output = { lighthouse: [], wrangler: [] } - # call the lighthouse service first as we are assuming that most labware scanned will be - # plates from Lighthouse Labs - output[:lighthouse] = Lighthouse.call_api(barcodes) + output = { wrangler: [] } - # keeping it simple for now, if all the responses are not CREATED, send ALL the barcodes - # to the wrangler - output[:wrangler] = Wrangler.call_api(barcodes) unless all_created?(output[:lighthouse]) + # Send all the barcodes to the wrangler + output[:wrangler] = Wrangler.call_api(barcodes) output end @@ -94,10 +88,6 @@ def generate_results(barcodes, responses) barcodes.each { |b| output[b] = { success: 'No' } } # loop through service responses to update 'output' with successes - # puts "DEBUG: responses: #{JSON.pretty_generate(responses)}" - responses[:lighthouse]&.select { |r| r[:code] == '201' }&.each do |r| - output[r[:barcode]] = parse_response(r, :Lighthouse) - end responses[:wrangler]&.select { |r| r[:code] == '201' }&.each do |r| output[r[:barcode]] = parse_response(r, :CGaP) end diff --git a/config/environments/development.rb b/config/environments/development.rb index 53d440d4..f3df4aaf 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -49,9 +49,6 @@ # https://github.com/sanger/wrangler config.wrangler_url = 'http://127.0.0.1:5000/wrangle' - # https://github.com/sanger/lighthouse - config.lighthouse_host = 'http://127.0.0.1:5000' - # config.logger.broadcast_messages = false # Use an evented file watcher to asynchronously detect changes in source code, diff --git a/config/environments/test.rb b/config/environments/test.rb index a4243fe2..367e75b8 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -46,7 +46,4 @@ # https://github.com/sanger/wrangler config.wrangler_url = 'http://example.com/wrangle' - - # https://github.com/sanger/lighthouse - config.lighthouse_host = 'http://127.0.0.1:5000' end diff --git a/lib/lighthouse.rb b/lib/lighthouse.rb deleted file mode 100644 index cda71078..00000000 --- a/lib/lighthouse.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -class Lighthouse - require 'net/http' - require 'json' - - def self.call_api(barcodes) - responses = [] - - begin - barcodes.each do |barcode| - url = URI.parse("#{Rails.application.config.lighthouse_host}/plates/new") - - Rails.logger.debug("Trying POST to '#{url}' with barcode '#{barcode}'") - - req = Net::HTTP::Post.new(url.to_s, 'Content-Type' => 'application/json') - req.body = { barcode: barcode }.to_json - - res = Net::HTTP.start(url.host, url.port) do |http| - http.request(req) - end - - responses << { barcode: barcode, code: res.code, body: Lighthouse.parse_body(res.body) } - end - rescue StandardError => e - Rails.logger.error(e) - nil - else - Rails.logger.info("Sent POST requests to lighthouse service: #{responses}") - end - responses - end - - def self.parse_body(body) - JSON.parse(body) - rescue StandardError - # return the body as is if not valid JSON - body - end -end diff --git a/test/controllers/process_plates_controller.rb b/test/controllers/process_plates_controller.rb index fcbfbd1d..d48017af 100644 --- a/test/controllers/process_plates_controller.rb +++ b/test/controllers/process_plates_controller.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'test_helper' -require 'lighthouse' require 'wrangler' class ProcessPlatesControllerTest < ActiveSupport::TestCase @@ -20,29 +19,17 @@ class ProcessPlatesControllerTest < ActiveSupport::TestCase assert_equal(ProcessPlatesController.new.all_created?([{ code: '201' }, { code: '200' }]), false) end - should 'call external services 1' do - Lighthouse.expects(:call_api).with(%w[123 456]).returns([]) + should 'call external services' do Wrangler.expects(:call_api).with(%w[123 456]) ProcessPlatesController.new.call_external_services(%w[123 456]) end - - should 'call external services 2' do - Lighthouse.expects(:call_api).with(%w[123 456]).returns([{ code: 400 }]) - Wrangler.expects(:call_api).with(%w[123 456]) - ProcessPlatesController.new.call_external_services(%w[123 456]) - end - - should 'call only lighthouse service' do - Lighthouse.expects(:call_api).returns([{ code: '201' }]) - ProcessPlatesController.new.call_external_services(%w[123 456]) - end end context '#generate_results' do should 'give failed results if no response' do barcodes = ['AB1'] - responses = { lighthouse: [], wrangler: [] } + responses = { wrangler: [] } expected_results = { 'AB1' => { success: 'No' } } @@ -54,14 +41,9 @@ class ProcessPlatesControllerTest < ActiveSupport::TestCase barcodes = %w[AB1 AB2 AB3] responses = { - lighthouse: [ + wrangler: [ generate_success_response('AB1', 'Purpose 1', ['Study 1', 'Study 2']), generate_success_response('AB2', 'Purpose 1', ['Study 1']), - generate_fail_response('AB3') - ], - wrangler: [ - generate_fail_response('AB1'), - generate_fail_response('AB2'), generate_success_response('AB3', 'Purpose 1', ['Study 1', 'Study 2']) ] } @@ -69,13 +51,13 @@ class ProcessPlatesControllerTest < ActiveSupport::TestCase expected_results = { 'AB1' => { success: 'Yes', - source: :Lighthouse, + source: :CGaP, purpose: 'Purpose 1', study: 'Study 1, Study 2' }, 'AB2' => { success: 'Yes', - source: :Lighthouse, + source: :CGaP, purpose: 'Purpose 1', study: 'Study 1' }, diff --git a/test/unit/lighthouse_test.rb b/test/unit/lighthouse_test.rb deleted file mode 100644 index 12247fab..00000000 --- a/test/unit/lighthouse_test.rb +++ /dev/null @@ -1,58 +0,0 @@ -# frozen_string_literal: true - -require 'test_helper' -require 'lighthouse' - -class LighthouseTest < ActiveSupport::TestCase - context 'Only call lighthouse API if a plate is received' do - setup do - ipi = FactoryBot.create(:instrument_processes_instrument) - @instrument = ipi.instrument - @instrument_process = ipi.instrument_process - - @input_params = { - instrument_process: @instrument_process.id.to_s, - source_plates: 'barcode_one' - } - end - - context "when the instrument process is 'receive plates' it" do - setup do - # Update the key of the instrument process to the one we are interested in - @instrument_process.update_attribute(:key, 'slf_receive_plates') - end - - should 'call the lighthouse API for one plate barcode' do - uri_template = Addressable::Template.new( - "#{Rails.application.config.lighthouse_host}/plates/new" - ) - - stub_request(:any, uri_template).to_return(status: 201) - - assert_equal( - [{ barcode: 'barcode_one', code: '201', body: '' }], - Lighthouse.call_api([@input_params[:source_plates]]) - ) - end - - should 'call the API for multiple unique plate barcodes' do - barcodes = %w[barcode_one barcode_two barcode_three] - - uri_template = Addressable::Template.new( - "#{Rails.application.config.lighthouse_host}/plates/new" - ) - - stub_request(:any, uri_template).to_return(status: 201) - - assert_equal( - [ - { barcode: 'barcode_one', code: '201', body: '' }, - { barcode: 'barcode_two', code: '201', body: '' }, - { barcode: 'barcode_three', code: '201', body: '' } - ], - Lighthouse.call_api(barcodes) - ) - end - end - end -end