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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23eb30fbb62a49330cd9e5db69140d6ccfeb408d7a44937d594f54e4b8482761
4
- data.tar.gz: 7d11e9e140129264da5d4a897096a10e15a01c68d6bd991a0645357cac0b6058
3
+ metadata.gz: 7295cfba1804dbd242c6e281b99ab6ade40e297c7377e0686a81a1e916bc460c
4
+ data.tar.gz: 18c1ffd8eb31d511e3d91cb36358eeaeaf0b801cbf55e714a1ad7ee66cac2768
5
5
  SHA512:
6
- metadata.gz: 30f786d6011a91db0826d647bd31a7a987c46a4ccc4bef38f0b08c537a29aac412ecde15e3a53241135ae9508a727489cc9071460f04a47f0ea2bf3575f79595
7
- data.tar.gz: a0150b0114a84e97d0ccb31aeb56bfe1500f9664e6e139912c9eb258bda05b9df1500facc100b5a0734aeaa7fa817f04d6b292b84c4476604a119a5379f329bf
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.8"
98
+ @sdk_version = "2.1.9"
99
99
  @gen_version = "internal"
100
- @user_agent = "noresponse-sdk/ruby 2.1.8 internal 1 noresponse"
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]]) }
@@ -1,7 +1,7 @@
1
1
  # typed: true
2
2
  # frozen_string_literal: true
3
3
 
4
- # Wait for a pending assessment. Hand-written beside the generated client.
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 no longer pending,
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. Raises WaitTimeoutError once timeout seconds have passed.
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
- response = assessments.get(assessment_id: assessment_id, timeout_ms: remaining_ms)
40
- return response.result unless response.result.status == Models::Shared::Status::PENDING
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
- raise WaitTimeoutError.new(assessment_id, response.result) if clock.call + delay > deadline
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noresponse
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.8
4
+ version: 2.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - NoResponse