Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Y24-061: Send Pool XP export message #4147

Merged
merged 34 commits into from
Jul 2, 2024

Conversation

sdjmchattie
Copy link
Contributor

Closes #4085

Changes proposed in this pull request

  • Extract code for creating compound samples.
  • Build an endpoint and job that will create an export message.
  • Encode the message with Avro and publish it to RabbitMQ.

Instructions for Reviewers

[All PRs] - Confirm PR template filled
[Feature Branches] - Review code

@sdjmchattie sdjmchattie self-assigned this Jun 21, 2024
@sdjmchattie sdjmchattie marked this pull request as draft June 21, 2024 14:33

def create
Rails.logger.debug "DEBUG: In ExportPoolXpToTractionController create"
# TODO: do we need to check the tube barcode is valid here?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO found

Rails.logger.debug "DEBUG: In ExportPoolXpToTractionController create"
# TODO: do we need to check the tube barcode is valid here?
Delayed::Job.enqueue ExportPoolXpToTractionJob.new(barcode)
# TODO: check if job queuing was successful or not and return appropriate status
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO found

# TODO: do we need to check the tube barcode is valid here?
Delayed::Job.enqueue ExportPoolXpToTractionJob.new(barcode)
# TODO: check if job queuing was successful or not and return appropriate status
# TODO: how to know if job successfully queued?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO found

Delayed::Job.enqueue ExportPoolXpToTractionJob.new(barcode)
# TODO: check if job queuing was successful or not and return appropriate status
# TODO: how to know if job successfully queued?
# TODO: does rendering something here send something back to Limber?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO found


def connection_params
connection_params = {
host: configatron.amqp.isg.host,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExportPoolXpToTractionJob#connection_params calls 'configatron.amqp' 5 times

@sdjmchattie sdjmchattie marked this pull request as ready for review June 25, 2024 11:08
boxBarcode: "Unspecified"
},
request: {
costCode: project.project_cost_code,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth doing project&.project_cost_code... not sure if tube.projects is able to return nil. If so actually, would need to do tube.projects&.first as well 🤔

Similar question with tube.studies.first and study.uuid

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm this is a tricky one. costCode is a required field and so is the study UUID. So if they were nil there's not a lot I could do to send the message and it might be better for that to bubble up to create an error log, rather than hide it in safe-chaining.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK gotcha. You could throw an explicit exception for it rather than let the nil pointer happen? So you could say something useful like 'expected data is not present - costcode'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes fair. If we leave it as is, the exception will say something about not being able to get attribute project_cost_code on nil object. If I do the safe-chaining as you suggest and it gets to the point where it's going to encode the message using Avro, you'll get a useful message back from fastavro about the field in the message not being allowed to be null.

sdjmchattie and others added 2 commits June 28, 2024 11:02
Co-authored-by: KatyTaylor <kt17@sanger.ac.uk>
Co-authored-by: KatyTaylor <kt17@sanger.ac.uk>
config/config.rb Outdated
configatron.amqp.isg.password = 'development'
configatron.amqp.isg.exchange = 'sequencescape'

configatron.amqp.schemas.registry_url = 'http://redpanda.uat.psd.sanger.ac.uk/subjects/'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want local config to be dependent on the UAT instance? Maybe it's not dependent...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had considered this when I made this choice and I don't know that there are any simple and easy answers. If I make it dependent on a local instance of RedPanda, that adds dependencies to Sequencescape when we already have so many. Although thinking about it again, you would only be able to run a local instance while on the VPN when you rely on UAT's RedPanda. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't have a connection to UAT's RedPanda, what will happen? If it breaks Sequencescape completely, I think that's not OK. If it just means this particular feature doesn't work, that's not too bad.

Similarly, I don't want a local RedPanda instance to be a requirement for developing SS locally... but if it was required for just this feature, wouldn't be too bad.

Would either of these work?

  1. Skip the check against the schema if one is not available? (in local only)
  2. Have a dummy schema in a file in the codebase that it uses in local only

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a cache to the system, which it probably should have had to start with. This means that you would need to connect to the UAT RedPanda the first time you trigger one of these jobs, but then you'd have a cached file of the schema to use in future calls. Of course, if you know the schema, you can also just dump it in the appropriately named cache file. I added some info to the README about this.


def preflight_errors(barcode)
# Check that the tube exists
tube = Tube.with_barcode(barcode).first
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not important, but again could change to the following

Suggested change
tube = Tube.with_barcode(barcode).first
tube = Tube.find_by_barcode(barcode)

@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'spec_helper'
require 'rails_helper'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened with these deleted 'rails_helper' lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read that you only need spec_helper during specs. rails_helper is implicitly part of that require. Correct me if you know otherwise.

Copy link
Contributor

@KatyTaylor KatyTaylor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finished reviewing! Only thing that needs working out I think is the schema dependency bit. Everything else was small.

app/jobs/export_pool_xp_to_traction_job.rb Show resolved Hide resolved
app/jobs/export_pool_xp_to_traction_job.rb Show resolved Hide resolved
app/jobs/export_pool_xp_to_traction_job.rb Show resolved Hide resolved
before_action :login_required, except: [:create]
skip_before_action :verify_authenticity_token

def create
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Api::V2::Bioscan::ExportPoolXpToTractionController#create has approx 6 statements

app/jobs/export_pool_xp_to_traction_job.rb Show resolved Hide resolved
Copy link
Contributor

@KatyTaylor KatyTaylor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addition of caching looks good I think!
Just pointed out a typo 😆

README.md Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know you could have .gitignore files in subdirectories 🤯

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, you can have them anywhere and they only apply to the files at the same level as them or lower.

Co-authored-by: KatyTaylor <kt17@sanger.ac.uk>
Copy link

codeclimate bot commented Jul 2, 2024

Code Climate has analyzed commit 2a714b4 and detected 19 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 19

The test coverage on the diff in this pull request is 97.2% (50% is the threshold).

This pull request will bring the total coverage in the repository to 86.7% (0.1% change).

View more on Code Climate.

@sdjmchattie sdjmchattie merged commit b0b713d into develop Jul 2, 2024
21 checks passed
@sdjmchattie sdjmchattie deleted the Y24-061-send-pool-xp-export-message branch July 2, 2024 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Y24-061: Research the best way to pass Pool XP tube export messages from Limber to RabbitMQ
3 participants