service_mesh 0.8.0 → 0.9.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/README.md +4 -0
- data/lib/service_mesh/types.rb +25 -0
- data/lib/service_mesh/version.rb +1 -1
- 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: 5f0ac7a9738980705b17f57104d32d2c29d56cd1be63b39982536b85d86ff027
|
|
4
|
+
data.tar.gz: 452f92225fcde530b31e3a8d5081ac86a9f563c7ab4259c2f6a46ade96580a17
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: abf49ec2682f1755242d6c92f10b3b00e6b6c7d75e293620fdc2a6dd7f522c98710b3c9d62abc13c1ad95d1edd90486b5429c6c41ef074d8fe3fbbf178dbdb26
|
|
7
|
+
data.tar.gz: bcc289f532966b861ca869bf059c7fcca9067913e7e434d08db7cef9d92bdb076a96c7e001f031741cf228c58ec8a97e106ed98a0106a4b2a9f442f4e9c68881
|
data/README.md
CHANGED
|
@@ -24,6 +24,10 @@ Requires Ruby 3.3 or newer. The gem has no runtime dependencies.
|
|
|
24
24
|
- Target Kinds are implemented as `:route` and `:topic`. A `Target` built with a kind outside the two
|
|
25
25
|
raises `KindMismatch`.
|
|
26
26
|
- `Message#payload` is always `Encoding::BINARY`.
|
|
27
|
+
- `Message#deadline` returns the message's `DEADLINE_KEY` as a `Time`, or `nil` when it is missing
|
|
28
|
+
or does not parse.
|
|
29
|
+
- `Message#expired?` is true when the message's `DEADLINE_KEY` has passed, or, on a request about to
|
|
30
|
+
be sent, when its `TIMEOUT_KEY` is no more than its `DEADLINE_OFFSET_KEY`.
|
|
27
31
|
- `Target#same_channel?` compares segments and kind and ignores metadata.
|
|
28
32
|
- The configuration key the specification defines, `DEPLOYMENT_GROUP_KEY`, which is runtime
|
|
29
33
|
configuration.
|
data/lib/service_mesh/types.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "time"
|
|
4
|
+
|
|
3
5
|
module ServiceMesh
|
|
4
6
|
KINDS = %i[route topic].freeze
|
|
5
7
|
|
|
@@ -82,6 +84,29 @@ module ServiceMesh
|
|
|
82
84
|
def initialize(target:, metadata: {}, payload: "")
|
|
83
85
|
super(target: target, metadata: metadata.to_h.freeze, payload: payload.to_s.b.freeze)
|
|
84
86
|
end
|
|
87
|
+
|
|
88
|
+
# The handler's deadline from DEADLINE_KEY, as a Time, or nil when the
|
|
89
|
+
# message has none or it does not parse.
|
|
90
|
+
def deadline
|
|
91
|
+
value = metadata[DEADLINE_KEY]
|
|
92
|
+
value && Time.iso8601(value)
|
|
93
|
+
rescue ArgumentError
|
|
94
|
+
nil
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Whether the message's deadline has passed. A message with DEADLINE_KEY
|
|
98
|
+
# compares it with now. A request about to be sent, with TIMEOUT_KEY and
|
|
99
|
+
# no DEADLINE_KEY, is expired when its timeout is no more than its
|
|
100
|
+
# DEADLINE_OFFSET_KEY, because its handler's deadline would fall before
|
|
101
|
+
# the request arrived.
|
|
102
|
+
def expired?
|
|
103
|
+
if (d = deadline)
|
|
104
|
+
return Time.now >= d
|
|
105
|
+
end
|
|
106
|
+
timeout = Integer(metadata[TIMEOUT_KEY].to_s, 10, exception: false)
|
|
107
|
+
return false if timeout.nil?
|
|
108
|
+
timeout <= Integer(metadata.fetch(DEADLINE_OFFSET_KEY, "0"), 10, exception: false).to_i
|
|
109
|
+
end
|
|
85
110
|
end
|
|
86
111
|
|
|
87
112
|
# A route target paired with a handler that returns a Message.
|
data/lib/service_mesh/version.rb
CHANGED