noresponse 2.1.8 → 2.1.9
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/lib/no_response/sdkconfiguration.rb +2 -2
- data/lib/no_response/wait.rb +25 -6
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7295cfba1804dbd242c6e281b99ab6ade40e297c7377e0686a81a1e916bc460c
|
|
4
|
+
data.tar.gz: 18c1ffd8eb31d511e3d91cb36358eeaeaf0b801cbf55e714a1ad7ee66cac2768
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 24ae1d8d916a9113c3e94bb4e77fa61c2ce7c878a6c08ba631df4a75bb3575c9a4769ce44bf74020e223b5fc15e0b4d8721d41b450720234195a3c9ff47d50b5
|
|
7
|
+
data.tar.gz: 87bc61f9f9e3abdb7bfa757a60654ced341dd1a09ffdb5311f5a16f9489cead2823961a535f26691571f3446fff582c6293d25730fbb96b14b0278303cedb4d0
|
|
@@ -95,9 +95,9 @@ module NoResponse
|
|
|
95
95
|
|
|
96
96
|
@language = "ruby"
|
|
97
97
|
@openapi_doc_version = "1"
|
|
98
|
-
@sdk_version = "2.1.
|
|
98
|
+
@sdk_version = "2.1.9"
|
|
99
99
|
@gen_version = "internal"
|
|
100
|
-
@user_agent = "noresponse-sdk/ruby 2.1.
|
|
100
|
+
@user_agent = "noresponse-sdk/ruby 2.1.9 internal 1 noresponse"
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
sig { returns([String, T::Hash[Symbol, String]]) }
|
data/lib/no_response/wait.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# typed: true
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
-
# Wait for
|
|
4
|
+
# Wait for an assessment to complete. Hand-written beside the generated client.
|
|
5
5
|
|
|
6
6
|
module NoResponse
|
|
7
7
|
# The assessment was still pending when the wait ran out. last is the
|
|
@@ -22,9 +22,12 @@ module NoResponse
|
|
|
22
22
|
|
|
23
23
|
class << self
|
|
24
24
|
|
|
25
|
-
# Poll client.assessments.get until the assessment is
|
|
25
|
+
# Poll client.assessments.get until the assessment's status is complete,
|
|
26
26
|
# sleeping for the Retry-After the API sends (at least 1 s) between
|
|
27
|
-
# polls.
|
|
27
|
+
# polls. Once timeout seconds have passed it returns a partial answer as
|
|
28
|
+
# it stands, its status still PARTIAL, and raises WaitTimeoutError if the
|
|
29
|
+
# assessment is still pending. A poll cut off by the deadline also
|
|
30
|
+
# returns the last partial answer instead of losing it.
|
|
28
31
|
def wait(client, assessment_id, **options)
|
|
29
32
|
poll(client.assessments, assessment_id, **options)
|
|
30
33
|
end
|
|
@@ -34,13 +37,29 @@ module NoResponse
|
|
|
34
37
|
raise ArgumentError, 'timeout must be positive' unless timeout.positive?
|
|
35
38
|
|
|
36
39
|
deadline = clock.call + timeout
|
|
40
|
+
last = T.let(nil, T.untyped)
|
|
37
41
|
loop do
|
|
38
42
|
remaining_ms = [((deadline - clock.call) * 1000).ceil, 1].max
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
begin
|
|
44
|
+
response = assessments.get(assessment_id: assessment_id, timeout_ms: remaining_ms)
|
|
45
|
+
rescue Faraday::TimeoutError
|
|
46
|
+
# Each poll is bounded by the time left, so a request timeout here
|
|
47
|
+
# is the wait running out: a partial answer from an earlier poll
|
|
48
|
+
# stands. Anything else, or a timeout before the deadline, raises.
|
|
49
|
+
raise unless clock.call >= deadline && last&.status == Models::Shared::Status::PARTIAL
|
|
50
|
+
|
|
51
|
+
return last
|
|
52
|
+
end
|
|
53
|
+
last = response.result
|
|
54
|
+
status = response.result.status
|
|
55
|
+
return response.result if status == Models::Shared::Status::COMPLETE
|
|
41
56
|
|
|
42
57
|
delay = retry_after(response.headers)
|
|
43
|
-
|
|
58
|
+
if clock.call + delay > deadline
|
|
59
|
+
return response.result if status == Models::Shared::Status::PARTIAL
|
|
60
|
+
|
|
61
|
+
raise WaitTimeoutError.new(assessment_id, response.result)
|
|
62
|
+
end
|
|
44
63
|
|
|
45
64
|
sleeper.call(delay)
|
|
46
65
|
end
|