Class: DaVinciPASTestKit::Jobs::SendPASSubscriptionNotification
- Inherits:
-
Object
- Object
- DaVinciPASTestKit::Jobs::SendPASSubscriptionNotification
- Includes:
- URLs, Sidekiq::Job, SubscriptionsTestKit::SubscriptionsR5BackportR4Client::SubscriptionSimulationUtils
- Defined in:
- lib/davinci_pas_test_kit/jobs/send_pas_subscription_notification.rb
Instance Method Summary collapse
- #authorization_header ⇒ Object
- #await_subscription_creation ⇒ Object
- #content_type_header ⇒ Object
- #headers ⇒ Object
- #perform(test_run_id, test_session_id, result_id, notification_bearer_token, notification_json, resume_token, notification_suite_id) ⇒ Object
- #persist_notification_request(response, tags) ⇒ Object
- #requests_repo ⇒ Object
- #rest_hook_connection ⇒ Object
- #results_repo ⇒ Object
- #send_event_notification ⇒ Object
- #send_notification(request_body) ⇒ Object
- #subscription ⇒ Object
- #subscription_full_url ⇒ Object
- #subscription_headers ⇒ Object
- #subscription_notification_endpoint ⇒ Object
- #subscription_topic ⇒ Object
-
#suite_id ⇒ Object
override the one from URLs.
- #test_still_waiting? ⇒ Boolean
- #test_suite_connection ⇒ Object
Methods included from URLs
#base_url, #fhir_subscription_url, #inquire_url, #resume_fail_url, #resume_pass_url, #submit_url, #token_url
Instance Method Details
#authorization_header ⇒ Object
81 82 83 84 |
# File 'lib/davinci_pas_test_kit/jobs/send_pas_subscription_notification.rb', line 81 def @authorization_header ||= @notification_bearer_token.present? ? { 'Authorization' => "Bearer #{@notification_bearer_token}" } : {} end |
#await_subscription_creation ⇒ Object
98 99 100 |
# File 'lib/davinci_pas_test_kit/jobs/send_pas_subscription_notification.rb', line 98 def await_subscription_creation sleep 0.5 until subscription.present? || !test_still_waiting? end |
#content_type_header ⇒ Object
70 71 72 |
# File 'lib/davinci_pas_test_kit/jobs/send_pas_subscription_notification.rb', line 70 def content_type_header @content_type_header ||= { 'Content-Type' => actual_mime_type(subscription) } end |
#headers ⇒ Object
57 58 59 |
# File 'lib/davinci_pas_test_kit/jobs/send_pas_subscription_notification.rb', line 57 def headers @headers ||= subscription_headers.merge(content_type_header).merge() end |
#perform(test_run_id, test_session_id, result_id, notification_bearer_token, notification_json, resume_token, notification_suite_id) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/davinci_pas_test_kit/jobs/send_pas_subscription_notification.rb', line 21 def perform(test_run_id, test_session_id, result_id, notification_bearer_token, notification_json, resume_token, notification_suite_id) @test_run_id = test_run_id @test_session_id = test_session_id @result_id = result_id @notification_bearer_token = notification_bearer_token @notification_json = notification_json @resume_token = resume_token @notification_suite_id = notification_suite_id await_subscription_creation # NOTE: currently must exist - see PASClientPendedSubmitTest sleep 1 return unless test_still_waiting? sleep rand(5..10) return unless test_still_waiting? send_event_notification end |
#persist_notification_request(response, tags) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/davinci_pas_test_kit/jobs/send_pas_subscription_notification.rb', line 117 def persist_notification_request(response, ) inferno_request_headers = headers.map { |name, value| { name:, value: } } inferno_response_headers = response.headers&.map { |name, value| { name:, value: } } requests_repo.create( verb: 'POST', url: response.env.url.to_s, direction: 'outgoing', status: response.status, request_body: response.env.request_body, response_body: response.env.response_body, test_session_id: @test_session_id, result_id: @result_id, request_headers: inferno_request_headers, response_headers: inferno_response_headers, tags: ) end |
#requests_repo ⇒ Object
41 42 43 |
# File 'lib/davinci_pas_test_kit/jobs/send_pas_subscription_notification.rb', line 41 def requests_repo @requests_repo ||= Inferno::Repositories::Requests.new end |
#rest_hook_connection ⇒ Object
61 62 63 64 |
# File 'lib/davinci_pas_test_kit/jobs/send_pas_subscription_notification.rb', line 61 def rest_hook_connection @rest_hook_connection ||= Faraday.new(url: subscription_notification_endpoint, request: { open_timeout: 30 }, headers:) end |
#results_repo ⇒ Object
45 46 47 |
# File 'lib/davinci_pas_test_kit/jobs/send_pas_subscription_notification.rb', line 45 def results_repo @results_repo ||= Inferno::Repositories::Results.new end |
#send_event_notification ⇒ Object
102 103 104 105 106 |
# File 'lib/davinci_pas_test_kit/jobs/send_pas_subscription_notification.rb', line 102 def send_event_notification event_json = derive_event_notification(@notification_json, subscription_full_url, subscription_topic, 1).to_json response = send_notification(event_json) persist_notification_request(response, [REST_HOOK_EVENT_NOTIFICATION_TAG]) end |
#send_notification(request_body) ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/davinci_pas_test_kit/jobs/send_pas_subscription_notification.rb', line 108 def send_notification(request_body) rest_hook_connection.post('', request_body) rescue Faraday::Error => e # Warning: This is a hack. If there is an error with the request such that we never get a response, we have # no clean way to persist that information for the Inferno test to check later. The solution here # is to persist the request anyway with a status of nil, using the error message as response body Faraday::Response.new(response_body: e., url: rest_hook_connection.url_prefix.to_s) end |
#subscription ⇒ Object
49 50 51 |
# File 'lib/davinci_pas_test_kit/jobs/send_pas_subscription_notification.rb', line 49 def subscription @subscription ||= find_subscription(@test_session_id) end |
#subscription_full_url ⇒ Object
90 91 92 |
# File 'lib/davinci_pas_test_kit/jobs/send_pas_subscription_notification.rb', line 90 def subscription_full_url @subscription_full_url ||= "#{fhir_subscription_url}/#{subscription.id}" end |
#subscription_headers ⇒ Object
74 75 76 77 78 79 |
# File 'lib/davinci_pas_test_kit/jobs/send_pas_subscription_notification.rb', line 74 def subscription_headers @subscription_headers ||= subscription.channel&.header&.each_with_object({}) do |header, hash| header_name, header_value = header.split(': ', 2) hash[header_name] = header_value end || {} end |
#subscription_notification_endpoint ⇒ Object
53 54 55 |
# File 'lib/davinci_pas_test_kit/jobs/send_pas_subscription_notification.rb', line 53 def subscription_notification_endpoint subscription&.channel&.endpoint end |
#subscription_topic ⇒ Object
86 87 88 |
# File 'lib/davinci_pas_test_kit/jobs/send_pas_subscription_notification.rb', line 86 def subscription_topic @subscription_topic ||= subscription&.criteria end |
#suite_id ⇒ Object
override the one from URLs
15 16 17 |
# File 'lib/davinci_pas_test_kit/jobs/send_pas_subscription_notification.rb', line 15 def suite_id @notification_suite_id end |
#test_still_waiting? ⇒ Boolean
94 95 96 |
# File 'lib/davinci_pas_test_kit/jobs/send_pas_subscription_notification.rb', line 94 def test_still_waiting? results_repo.find_waiting_result(test_run_id: @test_run_id) end |
#test_suite_connection ⇒ Object
66 67 68 |
# File 'lib/davinci_pas_test_kit/jobs/send_pas_subscription_notification.rb', line 66 def test_suite_connection @test_suite_connection ||= Faraday.new(base_url) end |