diff --git a/lib/inferno/config/boot/validator.rb b/lib/inferno/config/boot/validator.rb index dcfa7eecb1..0e4b252b9a 100644 --- a/lib/inferno/config/boot/validator.rb +++ b/lib/inferno/config/boot/validator.rb @@ -2,16 +2,15 @@ init do use :suites - # This process should only run once, - # so do not run this step on worker threads - # next if Sidekiq.server? + # This process should only run once, to start one job per validator, + # so skipping it on workers will start it only once from the "web" process + next if Sidekiq.server? Inferno::Repositories::TestSuites.new.all.each do |suite| suite.fhir_validators.each do |name, validators| - - validators.each do |validator| + validators.each_with_index do |validator, index| if validator.is_a? Inferno::DSL::FHIRResourceValidation::Validator - Inferno::Jobs.perform(Inferno::Jobs::InvokeValidatorSession, validator.url, validator.igs) + Inferno::Jobs.perform(Inferno::Jobs::InvokeValidatorSession, suite.id, name.to_s, index) end end end diff --git a/lib/inferno/jobs/invoke_validator_session.rb b/lib/inferno/jobs/invoke_validator_session.rb index d3a57ec1d2..d9099c119b 100644 --- a/lib/inferno/jobs/invoke_validator_session.rb +++ b/lib/inferno/jobs/invoke_validator_session.rb @@ -3,44 +3,17 @@ module Jobs class InvokeValidatorSession include Sidekiq::Worker - def perform(url, igs, disable_tx = false, display_issues_are_warnings = true) - request_body = { - cliContext: { - sv: '4.0.1', - displayWarnings: display_issues_are_warnings, - # txServer: nil, # -tx n/a - igs: igs || [] - }, - filesToValidate: [ - { - fileName: 'session_starter.json', - fileContent: FHIR::Patient.new.to_json, - fileType: 'json' - } - ] - } + def perform(suite_id, validator_name, validator_index) + suite = Inferno::Repositories::TestSuites.new.find suite_id + validator = suite.fhir_validators[validator_name.to_sym][validator_index] - request_body[:cliContext][:txServer] = nil if disable_tx + response_body = validator.validate(FHIR::Patient.new, 'http://hl7.org/fhir/StructureDefinition/Patient') - response = Faraday.new( - url, - request: { timeout: 600 } - ).post('validate', request_body.to_json, content_type: 'application/json') - - if response.body.start_with? '{' - res = JSON.parse(response.body) + if response_body.start_with? '{' + res = JSON.parse(response_body) session_id = res['sessionId'] - # TODO: (FI-2311) store this session ID so it can be referenced as needed, - # instead of iterating through all test suites to find where it goes - Inferno::Repositories::TestSuites.new.all.each do |suite| - suite.fhir_validators.each do |name, validators| - validators.each do |validator| - if validator.url == url and validator.igs == igs - validator.session_id = session_id - end - end - end - end + # TODO: (FI-2311) store this session ID so it can be referenced as needed + validator.session_id = session_id else Inferno::Application['logger'].error("InvokeValidatorSession - error calling validator. #{response.inspect}") end