patient_http 1.6.0 → 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.
- checksums.yaml +4 -4
- data/ARCHITECTURE.md +8 -7
- data/CHANGELOG.md +39 -0
- data/README.md +540 -514
- data/VERSION +1 -1
- data/lib/patient_http/callback_args.rb +53 -48
- data/lib/patient_http/callback_validator.rb +11 -7
- data/lib/patient_http/class_helper.rb +6 -7
- data/lib/patient_http/client.rb +28 -22
- data/lib/patient_http/client_pool.rb +134 -39
- data/lib/patient_http/completion_executor.rb +20 -20
- data/lib/patient_http/configuration.rb +367 -119
- data/lib/patient_http/connection_endpoint.rb +150 -0
- data/lib/patient_http/encryptor.rb +28 -18
- data/lib/patient_http/error.rb +24 -18
- data/lib/patient_http/external_storage.rb +42 -38
- data/lib/patient_http/http_error.rb +30 -26
- data/lib/patient_http/http_headers.rb +57 -26
- data/lib/patient_http/immediate_retries.rb +98 -0
- data/lib/patient_http/inline_task_handler.rb +15 -10
- data/lib/patient_http/lifecycle_manager.rb +39 -40
- data/lib/patient_http/outgoing_request.rb +25 -23
- data/lib/patient_http/payload.rb +28 -26
- data/lib/patient_http/payload_store/active_record_store.rb +31 -34
- data/lib/patient_http/payload_store/base.rb +42 -46
- data/lib/patient_http/payload_store/file_store.rb +22 -26
- data/lib/patient_http/payload_store/redis_store.rb +28 -34
- data/lib/patient_http/payload_store/s3_store.rb +25 -28
- data/lib/patient_http/payload_store.rb +2 -0
- data/lib/patient_http/processor.rb +111 -79
- data/lib/patient_http/processor_observer.rb +65 -59
- data/lib/patient_http/rails/engine.rb +13 -8
- data/lib/patient_http/redirect_error.rb +50 -41
- data/lib/patient_http/redirect_helper.rb +38 -38
- data/lib/patient_http/request.rb +70 -46
- data/lib/patient_http/request_error.rb +47 -42
- data/lib/patient_http/request_helper.rb +142 -119
- data/lib/patient_http/request_preparer.rb +13 -10
- data/lib/patient_http/request_task.rb +113 -84
- data/lib/patient_http/request_template.rb +87 -64
- data/lib/patient_http/response.rb +58 -52
- data/lib/patient_http/response_reader.rb +66 -65
- data/lib/patient_http/secret_manager.rb +34 -30
- data/lib/patient_http/secret_reference.rb +33 -26
- data/lib/patient_http/synchronous_executor.rb +67 -95
- data/lib/patient_http/task_handler.rb +23 -19
- data/lib/patient_http/time_helper.rb +8 -8
- data/lib/patient_http.rb +311 -186
- data/patient_http.gemspec +3 -2
- metadata +20 -4
|
@@ -10,13 +10,13 @@ module PatientHttp
|
|
|
10
10
|
#
|
|
11
11
|
# @api private
|
|
12
12
|
class CompletionExecutor
|
|
13
|
-
#
|
|
13
|
+
# Creates the executor and starts its worker threads.
|
|
14
14
|
#
|
|
15
|
-
# @param threads [Integer]
|
|
16
|
-
# @param logger [Logger, nil]
|
|
17
|
-
# @param thread_name_prefix [String]
|
|
18
|
-
# @param on_finished [#call, nil]
|
|
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
|
-
#
|
|
37
|
+
# Enqueues a job for execution.
|
|
38
38
|
#
|
|
39
|
-
# @param job [#call]
|
|
40
|
-
# @raise [ClosedQueueError]
|
|
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
|
-
#
|
|
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
|
-
#
|
|
60
|
+
# Returns whether the given thread is one of this executor's workers.
|
|
61
61
|
#
|
|
62
|
-
# @param thread [Thread]
|
|
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
|
-
#
|
|
69
|
-
# and exit
|
|
70
|
-
#
|
|
71
|
-
#
|
|
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
|
-
#
|
|
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]
|
|
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
|
-
#
|
|
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.
|