Class: PatientHttp::SolidQueue::CallbackJob Private

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
lib/patient_http/solid_queue/callback_job.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.

Active Job that invokes callback services for HTTP request results.

Receives serialized Response or Error data and invokes the appropriate callback service method (+on_complete+ or on_error).

Instance Method Summary collapse

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.

Parameters:

  • data (Hash)

    Response or Error data (possibly a storage reference)

  • result_type (String)

    "response" or "error" indicating the type of result

  • callback_service_name (String)

    Fully qualified callback service class name



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/patient_http/solid_queue/callback_job.rb', line 47

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

  ref_data = PatientHttp::ExternalStorage.storage_ref?(data) ? data : nil
  actual_data = ref_data ? PatientHttp::SolidQueue.external_storage.fetch(data) : data
  actual_data = PatientHttp::SolidQueue.decrypt(actual_data)

  if result_type == "response"
    response = PatientHttp::Response.load(actual_data)
    PatientHttp::SolidQueue.invoke_completion_callbacks(response)
    callback_service.on_complete(response)
  elsif result_type == "error"
    error = PatientHttp::Error.load(actual_data)
    PatientHttp::SolidQueue.invoke_error_callbacks(error)
    callback_service.on_error(error)
  else
    raise ArgumentError, "Unknown result_type: #{result_type}"
  end

  # Only delete the stored payload after the callback succeeds so that
  # retries can still fetch it. Discarded jobs are cleaned up by the
  # after_discard hook.
  PatientHttp::SolidQueue.external_storage.delete(ref_data) if ref_data
end