Class: PatientHttp::SolidQueue::RequestExecutor
- Inherits:
-
Object
- Object
- PatientHttp::SolidQueue::RequestExecutor
- Defined in:
- lib/patient_http/solid_queue/request_executor.rb
Overview
Helper methods for executing HTTP requests asynchronously.
Class Method Summary collapse
-
.execute(request, callback:, active_job_data: nil, synchronous: false, callback_args: nil, raise_error_responses: false, request_id: nil, processor_name: nil) ⇒ String
private
Execute the request directly on the async processor.
Class Method Details
.execute(request, callback:, active_job_data: nil, synchronous: false, callback_args: nil, raise_error_responses: false, request_id: nil, processor_name: nil) ⇒ String
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.
Execute the request directly on the async processor.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/patient_http/solid_queue/request_executor.rb', line 21 def execute( request, callback:, active_job_data: nil, synchronous: false, callback_args: nil, raise_error_responses: false, request_id: nil, processor_name: nil ) active_job_data = validate_active_job_data(active_job_data) task_handler = TaskHandler.new(active_job_data) config = PatientHttp::SolidQueue.configuration # Resolve the processor profile up front so the task is built with # the options of the processor that will run it. An unknown name # falls back to the base configuration here and is reported below. name = (processor_name || request.processor || :default).to_sym profile_config = config.processor_profiles.key?(name) ? config.processor_config(name) : config task = PatientHttp::RequestTask.new( request: request, task_handler: task_handler, callback: callback, callback_args: callback_args, raise_error_responses: raise_error_responses, id: request_id, default_max_redirects: profile_config.max_redirects ) if synchronous || async_disabled? PatientHttp::SynchronousExecutor.new( task, config: profile_config, on_complete: ->(response) { PatientHttp::SolidQueue.invoke_completion_callbacks(response) }, on_error: ->(error) { PatientHttp::SolidQueue.invoke_error_callbacks(error) } ).call return task.id end # Look up the named processor. An unknown name raises so the job # lands in Active Job's retry mechanism instead of being dropped; # this covers rolling deploys where an old process has not # configured a new profile yet. processor = PatientHttp::SolidQueue.processor(name) if processor.nil? && !config.processor_profiles.key?(name) raise PatientHttp::UnknownProcessorError, "No processor profile configured for #{name.inspect}" end unless processor&.running? raise PatientHttp::NotRunningError, "Cannot enqueue request: processor is not running" end # Advisory capacity check before enqueueing. A real enqueue writes # the durable registry record before the authoritative capacity # check, so a full processor would pay a database insert and delete # just to be rejected. This peek rejects for free; the race where # capacity fills after the peek falls through to the normal # rejection path. unless processor.capacity_available? raise PatientHttp::MaxCapacityError, "Cannot enqueue request: processor #{name} is at max capacity (#{processor.config.max_connections} connections)" end processor.enqueue(task) task.id end |