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

add extractor name to prediction request for new workflow #186

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/services/batch/prediction/create_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ def initialize(prediction_job, bajor_client = Bajor::Client.new)

def run
begin
bajor_job_url = bajor_client.create_prediction_job(prediction_job.manifest_url)
subject_set_id = prediction_job.subject_set_id
context = Context.where(active_subject_set_id: subject_set_id).or(Context.where(pool_subject_set_id: subject_set_id)).order(Arel.sql("CASE WHEN active_subject_set_id = #{subject_set_id} THEN 0 ELSE 1 END"))

workflow_name = nil
if context.first.present?
workflow_name = context.first.extractor_name
end

bajor_job_url = bajor_client.create_prediction_job(prediction_job.manifest_url, workflow_name)
prediction_job.update(state: :submitted, service_job_url: bajor_job_url, message: '')
rescue Bajor::Client::Error => e
# mark the jobs as failed and record the client error message
Expand Down
4 changes: 2 additions & 2 deletions lib/bajor/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def create_training_job(manifest_path, workflow_name='cosmic_dawn')
bajor_training_job_tracking_url(bajor_response['id'])
end

def create_prediction_job(manifest_url)
def create_prediction_job(manifest_url, workflow_name='cosmic_dawn')
bajor_response = self.class.post(
'/prediction/jobs/',
body: { manifest_url: manifest_url }.to_json,
body: { manifest_url: manifest_url, opts: { 'workflow_name': workflow_name } }.to_json,
headers: JSON_HEADERS
)

Expand Down
6 changes: 3 additions & 3 deletions spec/lib/bajor/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
RSpec.describe Bajor::Client do
let(:bajor_client) { described_class.new }
let(:bajor_host) { 'https://bajor.zooniverse.org' }
let(:run_opts) { '--schema cosmic_dawn' }
let(:workflow_name) { 'cosmic_dawn' }
let(:request_headers) do
{
'Accept' => 'application/json',
Expand All @@ -19,8 +21,6 @@
describe 'create_training_job' do
let(:request_url) { "#{bajor_host}/training/jobs/" }
let(:catalogue_manifest_path) { 'training_catalogues/manifest_path.csv' }
let(:run_opts) { '--schema cosmic_dawn' }
let(:workflow_name) { 'cosmic_dawn' }
let(:request_body) do
{
manifest_path: catalogue_manifest_path,
Expand Down Expand Up @@ -93,7 +93,7 @@
let(:request_url) { "#{bajor_host}/prediction/jobs/" }
let(:manifest_url) { 'https://manifest-host.zooniverse.org/manifest.csv' }
let(:request_body) do
{ manifest_url: manifest_url }
{ manifest_url: manifest_url, opts: { workflow_name: workflow_name} }
end
let(:job_id) { '3ed68115-dc36-4f66-838c-a52869031c9c' }
let(:bajor_response_body) do
Expand Down
5 changes: 3 additions & 2 deletions spec/services/batch/prediction/create_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
RSpec.describe Batch::Prediction::CreateJob do
describe '#run' do
let(:manifest_url) { 'https://manifest-host.zooniverse.org/manifest.csv' }
let(:context){Context.first}
let(:prediction_job) do
PredictionJob.new(
manifest_url: manifest_url,
state: :pending,
subject_set_id: 1,
subject_set_id: context.active_subject_set_id,
probability_threshold: 0.5,
randomisation_factor: 0.5
)
Expand All @@ -33,7 +34,7 @@

it 'calls the bajor client service to create a prediction job' do
prediction_create_job.run
expect(bajor_client_double).to have_received(:create_prediction_job).with(manifest_url).once
expect(bajor_client_double).to have_received(:create_prediction_job).with(manifest_url, context.extractor_name).once
end

it 'updates the state tracking info on the prediction job resource' do
Expand Down
Loading