Class: PatientHttp::Sidekiq::RequestWorker Private

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job
Defined in:
lib/patient_http/sidekiq/request_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 for executing HTTP requests asynchronously.

This worker is enqueued when calling PatientHttp::Sidekiq.get, PatientHttp::Sidekiq.post, etc. It allows HTTP requests to be made from anywhere in your code (not just Sidekiq jobs) while still processing them through the async HTTP processor.

When the request completes, the specified callback service's on_complete or on_error method is invoked via CallbackWorker.

Instance Method Summary collapse

Instance Method Details

#perform(data, callback_service_name, raise_error_responses, callback_args, request_id) ⇒ void

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.

This method returns an undefined value.

Perform the HTTP request.

Parameters:

  • data (Hash)

    Request data (possibly a storage reference) with keys:

    • "http_method" [String] HTTP method (get, post, put, patch, delete)
    • "url" [String] The request URL
    • "headers" [Hash] Request headers
    • "body" [String, nil] Request body
    • "timeout" [Numeric, nil] Request timeout
    • "max_redirects" [Integer, nil] Maximum redirects to follow
  • callback_service_name (String)

    Fully qualified callback service class name

  • raise_error_responses (Boolean, nil)

    Whether to treat non-2xx responses as errors; nil is treated as false

  • callback_args (Hash, nil)

    Arguments to pass to the callback

  • request_id (String, nil)

    Unique request ID for tracking



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/patient_http/sidekiq/request_worker.rb', line 44

def perform(data, callback_service_name, raise_error_responses, callback_args, request_id)
  # Fetch from external storage if needed
  actual_data = PatientHttp::ExternalStorage.storage_ref?(data) ? Sidekiq.external_storage.fetch(data) : data
  actual_data = Sidekiq.decrypt(actual_data)

  request = PatientHttp::Request.load(actual_data)
  sidekiq_job = Sidekiq::Context.current_job

  # The stored payload must not be deleted here: this job hash is re-pushed
  # for Sidekiq retries (e.g. MaxCapacityError), processor shutdown retries,
  # and crash recovery, all of which need to fetch the payload again.
  # TaskHandler deletes it when the request completes.
  RequestExecutor.execute(
    request,
    callback: callback_service_name,
    raise_error_responses: raise_error_responses,
    callback_args: callback_args,
    sidekiq_job: sidekiq_job,
    request_id: request_id
  )
end