Class: PatientHttp::Sidekiq::CallbackWorker Private
- Inherits:
-
Object
- Object
- PatientHttp::Sidekiq::CallbackWorker
- Includes:
- Sidekiq::Job
- Defined in:
- lib/patient_http/sidekiq/callback_worker.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Sidekiq worker that invokes callback services for HTTP request results.
This worker receives serialized Response or Error data and invokes the appropriate callback service method (on_complete or on_error).
Callback services are plain Ruby classes that define on_complete and on_error instance methods:
Instance Method Summary collapse
-
#perform(data, result_type, callback_service_name) ⇒ Object
private
Perform the callback invocation.
Instance Method Details
#perform(data, result_type, callback_service_name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Perform the callback invocation.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/patient_http/sidekiq/callback_worker.rb', line 69 def perform(data, result_type, callback_service_name) callback_service_class = PatientHttp::ClassHelper.resolve_class_name(callback_service_name) callback_service = callback_service_class.new # Fetch from external storage if needed ref_data = Sidekiq.external_storage.storage_ref?(data) ? data : nil actual_data = ref_data ? Sidekiq.external_storage.fetch(data) : data actual_data = Sidekiq.decrypt(actual_data) begin if result_type == "response" response = PatientHttp::Response.load(actual_data) PatientHttp::Sidekiq.invoke_completion_callbacks(response) callback_service.on_complete(response) elsif result_type == "error" error = PatientHttp::Error.load(actual_data) PatientHttp::Sidekiq.invoke_error_callbacks(error) callback_service.on_error(error) else raise ArgumentError, "Unknown result_type: #{result_type}" end ensure Sidekiq.external_storage.delete(ref_data) if ref_data end end |