volcano-sdk 0.9.3 → 0.9.4

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: bb4b4a206147014ad99f42983e545238fd1c46600a127cbe932db4877afd6db9
4
- data.tar.gz: 5064a928176a3dd8350d066000c405c1d03b87499b3cbc9bd0a9534b65785247
3
+ metadata.gz: e4fdce577eb0f97e2359db37774f29986e40c24d7d8b4bf64b67ccca4c96ea85
4
+ data.tar.gz: 5bb422eb1a068e899aa6de617f2bfc4bf78128698009f384c37254c753ae3ea1
5
5
  SHA512:
6
- metadata.gz: 9ea3fff976b1358651b6f0117a23ccb353edb01139b9876f07b2bca473acd607550779702d0a8821c5cc612194e0fb51f279df52fd41a192b44916d60dd50844
7
- data.tar.gz: 7b4761b2c1c25f131968de7662668f04c83ad90fe13532b4b7b277685fe23966ca585f578d6337bbe28dbf9c1a584dc38c0d243420f56851af559f0f6fbce085
6
+ metadata.gz: b0cd140b083357a515a32e3f0dccbc5280519cbaa6f08f1881f745675b979193dd6bd1ddb9e6b415ac55cdabbdcfda44a1b157e97bc2c9f0f1370292ff377922
7
+ data.tar.gz: 711a49849712a130ac0da5256bef2297428fd3fa2e69e91853842be89752b0e2406e66dc88c88fea78dea29bdfdfd6146701b4aa6a564638a24dad8c42904aab
@@ -14,7 +14,14 @@ module Volcano
14
14
  Resolution = Data.define(:function_id, :invoke_url)
15
15
 
16
16
  # A cached resolve result. A nil resolution is a remembered miss.
17
- Outcome = Data.define(:resolution)
17
+ Outcome = Data.define(:resolution, :failure)
18
+
19
+ Failure = Data.define(:message, :code, :retry_after) do
20
+ def exception
21
+ Error::NotFoundError.new(message.dup, status: 404, code: code&.dup, retry_after: retry_after)
22
+ end
23
+ end
24
+ private_constant :Failure
18
25
 
19
26
  Entry = Data.define(:outcome, :expires_at)
20
27
  private_constant :Entry
@@ -72,13 +79,15 @@ module Volcano
72
79
 
73
80
  # Caches a resolution for the server-advertised lifetime.
74
81
  def store(api_url, authorization, name, resolution, ttl_seconds)
75
- write([api_url, authorization, name], Outcome.new(resolution: resolution), ttl_seconds)
82
+ write([api_url, authorization, name], Outcome.new(resolution: resolution, failure: nil), ttl_seconds)
76
83
  end
77
84
 
78
85
  # Remembers briefly that a name does not resolve, so a caller retrying an
79
86
  # unknown name in a loop does not re-ask the server on every attempt.
80
- def store_missing(api_url, authorization, name)
81
- write([api_url, authorization, name], Outcome.new(resolution: nil), NEGATIVE_TTL_SECONDS)
87
+ def store_missing(api_url, authorization, name, error)
88
+ failure = Failure.new(message: error.message.dup.freeze, code: error.code&.dup&.freeze,
89
+ retry_after: error.retry_after)
90
+ write([api_url, authorization, name], Outcome.new(resolution: nil, failure: failure), NEGATIVE_TTL_SECONDS)
82
91
  end
83
92
 
84
93
  # Drops one cached resolution that turned out to be stale.
@@ -88,15 +88,17 @@ module Volcano
88
88
  resolved = Transport.invoke do
89
89
  @transport.resolve_function_for_invocation(authorization: authorization, name: name)
90
90
  end
91
- FunctionResolution.store_missing(@api_url, authorization, name) if resolved.status == 404
92
91
  payload = Transport.body(resolved, 200)
93
92
  resolution = resolved_resolution(payload)
94
93
  FunctionResolution.store(@api_url, authorization, name, resolution, cache_ttl(payload))
95
94
  resolution
95
+ rescue Error::NotFoundError => e
96
+ FunctionResolution.store_missing(@api_url, authorization, name, e)
97
+ raise
96
98
  end
97
99
 
98
100
  def cached_resolution(cached)
99
- cached.resolution || raise(Error::NotFoundError.new('Function was not found', status: 404))
101
+ cached.resolution || raise(cached.failure.exception)
100
102
  end
101
103
 
102
104
  def validate_invocation(name, payload)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Volcano
4
- VERSION = '0.9.3'
4
+ VERSION = '0.9.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: volcano-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kong