patient_http 1.6.1 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/ARCHITECTURE.md +8 -7
  3. data/CHANGELOG.md +29 -0
  4. data/README.md +539 -515
  5. data/VERSION +1 -1
  6. data/lib/patient_http/callback_args.rb +53 -48
  7. data/lib/patient_http/callback_validator.rb +11 -7
  8. data/lib/patient_http/class_helper.rb +6 -7
  9. data/lib/patient_http/client.rb +28 -22
  10. data/lib/patient_http/client_pool.rb +134 -39
  11. data/lib/patient_http/completion_executor.rb +20 -20
  12. data/lib/patient_http/configuration.rb +367 -119
  13. data/lib/patient_http/connection_endpoint.rb +150 -0
  14. data/lib/patient_http/encryptor.rb +28 -18
  15. data/lib/patient_http/error.rb +24 -18
  16. data/lib/patient_http/external_storage.rb +42 -38
  17. data/lib/patient_http/http_error.rb +30 -26
  18. data/lib/patient_http/http_headers.rb +35 -29
  19. data/lib/patient_http/immediate_retries.rb +98 -0
  20. data/lib/patient_http/inline_task_handler.rb +15 -10
  21. data/lib/patient_http/lifecycle_manager.rb +39 -40
  22. data/lib/patient_http/outgoing_request.rb +25 -23
  23. data/lib/patient_http/payload.rb +28 -26
  24. data/lib/patient_http/payload_store/active_record_store.rb +31 -34
  25. data/lib/patient_http/payload_store/base.rb +42 -46
  26. data/lib/patient_http/payload_store/file_store.rb +22 -26
  27. data/lib/patient_http/payload_store/redis_store.rb +28 -34
  28. data/lib/patient_http/payload_store/s3_store.rb +25 -28
  29. data/lib/patient_http/payload_store.rb +2 -0
  30. data/lib/patient_http/processor.rb +111 -79
  31. data/lib/patient_http/processor_observer.rb +65 -59
  32. data/lib/patient_http/rails/engine.rb +13 -8
  33. data/lib/patient_http/redirect_error.rb +50 -41
  34. data/lib/patient_http/redirect_helper.rb +38 -38
  35. data/lib/patient_http/request.rb +70 -46
  36. data/lib/patient_http/request_error.rb +47 -42
  37. data/lib/patient_http/request_helper.rb +142 -119
  38. data/lib/patient_http/request_preparer.rb +13 -10
  39. data/lib/patient_http/request_task.rb +113 -84
  40. data/lib/patient_http/request_template.rb +87 -64
  41. data/lib/patient_http/response.rb +58 -52
  42. data/lib/patient_http/response_reader.rb +66 -65
  43. data/lib/patient_http/secret_manager.rb +34 -30
  44. data/lib/patient_http/secret_reference.rb +33 -26
  45. data/lib/patient_http/synchronous_executor.rb +67 -95
  46. data/lib/patient_http/task_handler.rb +23 -19
  47. data/lib/patient_http/time_helper.rb +8 -8
  48. data/lib/patient_http.rb +311 -186
  49. data/patient_http.gemspec +3 -2
  50. metadata +21 -5
@@ -10,13 +10,13 @@ module PatientHttp
10
10
  #
11
11
  # @api private
12
12
  class CompletionExecutor
13
- # Initialize the executor and start its worker threads.
13
+ # Creates the executor and starts its worker threads.
14
14
  #
15
- # @param threads [Integer] number of worker threads
16
- # @param logger [Logger, nil] logger for unexpected job errors
17
- # @param thread_name_prefix [String] prefix for worker thread names
18
- # @param on_finished [#call, nil] invoked after each job completes, outside
19
- # any executor lock, so the owner can re-check idle conditions
15
+ # @param threads [Integer] Number of worker threads.
16
+ # @param logger [Logger, nil] Logger for unexpected job errors.
17
+ # @param thread_name_prefix [String] Prefix for worker thread names.
18
+ # @param on_finished [#call, nil] Invoked after each job completes, outside
19
+ # any executor lock, so the owner can re-check idle conditions.
20
20
  def initialize(threads:, logger: nil, thread_name_prefix: "patient-http-completion", on_finished: nil)
21
21
  @queue = Thread::Queue.new
22
22
  @logger = logger
@@ -34,10 +34,10 @@ module PatientHttp
34
34
  end
35
35
  end
36
36
 
37
- # Enqueue a job for execution.
37
+ # Enqueues a job for execution.
38
38
  #
39
- # @param job [#call] the job to run
40
- # @raise [ClosedQueueError] if the executor has been shut down
39
+ # @param job [#call] The job to run.
40
+ # @raise [ClosedQueueError] If the executor has been shut down.
41
41
  # @return [void]
42
42
  def enqueue(job)
43
43
  @mutex.synchronize { @outstanding += 1 }
@@ -50,30 +50,30 @@ module PatientHttp
50
50
  nil
51
51
  end
52
52
 
53
- # Check whether the executor has no queued or running jobs.
53
+ # Returns whether the executor has no queued or running jobs.
54
54
  #
55
55
  # @return [Boolean]
56
56
  def idle?
57
57
  @mutex.synchronize { @outstanding == 0 }
58
58
  end
59
59
 
60
- # Check whether the given thread is one of this executor's workers.
60
+ # Returns whether the given thread is one of this executor's workers.
61
61
  #
62
- # @param thread [Thread] the thread to check
62
+ # @param thread [Thread] The thread to check.
63
63
  # @return [Boolean]
64
64
  def worker_thread?(thread = Thread.current)
65
65
  @threads.include?(thread)
66
66
  end
67
67
 
68
- # Shut down the executor: close the queue so workers drain remaining jobs
69
- # and exit, then join them within the timeout. Workers still alive after
70
- # the deadline are killed; their tasks remain durably tracked and are
71
- # recovered by the owner's re-enqueue logic.
68
+ # Shuts down the executor. The queue is closed, so the workers run the
69
+ # remaining jobs and exit. The executor waits for the workers until the
70
+ # timeout, and then kills the workers that are still alive. Their tasks
71
+ # stay tracked, and the owner re-enqueues them.
72
72
  #
73
- # Safe to call more than once and from a worker thread itself (the
74
- # current thread is never joined or killed).
73
+ # You can call this method more than once, and from a worker thread. The
74
+ # current thread is never joined or killed.
75
75
  #
76
- # @param timeout [Numeric] seconds to wait for workers to drain
76
+ # @param timeout [Numeric] Seconds to wait for workers to drain.
77
77
  # @return [void]
78
78
  def shutdown(timeout: 5)
79
79
  @queue.close
@@ -96,7 +96,7 @@ module PatientHttp
96
96
 
97
97
  private
98
98
 
99
- # Drop jobs left in the closed queue by workers that were killed at the
99
+ # Drops jobs left in the closed queue by workers that were killed at the
100
100
  # shutdown deadline. Those jobs can never run, so they must stop counting
101
101
  # against the outstanding total or the executor would never report itself
102
102
  # idle again.