Skip to content

Commit

Permalink
FI-2234: migrate job to start via boot process
Browse files Browse the repository at this point in the history
  • Loading branch information
dehall committed Nov 13, 2023
1 parent 42b435d commit 61e6b4e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
20 changes: 20 additions & 0 deletions lib/inferno/config/boot/validator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Inferno::Application.boot(:validator) do
init do
use :suites

# This process should only run once,
# so do not run this step on worker threads
# next if Sidekiq.server?

Inferno::Repositories::TestSuites.new.all.each do |suite|
suite.fhir_validators.each do |name, validators|

validators.each do |validator|
if validator.is_a? Inferno::DSL::FHIRResourceValidation::Validator
Inferno::Jobs.perform(Inferno::Jobs::InvokeValidatorSession, validator.url, validator.igs)
end
end
end
end
end
end
3 changes: 1 addition & 2 deletions lib/inferno/dsl/fhir_resource_validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ def self.included(klass)

class Validator
attr_reader :requirements
attr_accessor :session_id

# @private
def initialize(requirements = nil, &)
instance_eval(&)
@requirements = requirements

Jobs.perform(Jobs::InvokeValidatorSession, url, igs)
end

# @private
Expand Down
22 changes: 13 additions & 9 deletions lib/inferno/jobs/invoke_validator_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def perform(url, igs, disable_tx = false, display_issues_are_warnings = true)
},
filesToValidate: [
{
fileName: 'manually_entered_file.json',
fileName: 'session_starter.json',
fileContent: FHIR::Patient.new.to_json,
fileType: 'json'
}
Expand All @@ -22,8 +22,6 @@ def perform(url, igs, disable_tx = false, display_issues_are_warnings = true)

request_body[:cliContext][:txServer] = nil if disable_tx

# puts request_body.to_json

response = Faraday.new(
url,
request: { timeout: 600 }
Expand All @@ -32,13 +30,19 @@ def perform(url, igs, disable_tx = false, display_issues_are_warnings = true)
if response.body.start_with? '{'
res = JSON.parse(response.body)
session_id = res['sessionId']
puts session_id
# TODO: put this session ID somewhere so we can look it up

# 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
else
puts response.body
puts response.status
# TODO: something went wrong. now what?
Inferno::Application['logger'].error("InvokeValidatorSession - error calling validator. #{response.inspect}")
end
end
end
Expand Down

0 comments on commit 61e6b4e

Please sign in to comment.