service_mesh 0.7.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bcd6eb2f6dc67794526d4693af7199f0f34d6b6007f580ed9040af7ab1639ac9
4
- data.tar.gz: 7bf3175253dd81a2c60865ee18eb937b9aa50dc164b90ea61dbae5081cb3383d
3
+ metadata.gz: 5f0ac7a9738980705b17f57104d32d2c29d56cd1be63b39982536b85d86ff027
4
+ data.tar.gz: 452f92225fcde530b31e3a8d5081ac86a9f563c7ab4259c2f6a46ade96580a17
5
5
  SHA512:
6
- metadata.gz: 3c5b49162b557e5ce7c474dad8e9063ee497a4ce5a8128137c8687e3e7c704987ca58648bbd56c010a8408d610f60198e9672a61b74b81e94b2c8a0891e12a0d
7
- data.tar.gz: 6c976851042fc53273b5721d84607759a1bcadcc4813ca2df6b340dc420aa07c9d2dde8c1f537f05993590b13bf22ab4159485832287d6edd67ca9d33c1ebf74
6
+ metadata.gz: abf49ec2682f1755242d6c92f10b3b00e6b6c7d75e293620fdc2a6dd7f522c98710b3c9d62abc13c1ad95d1edd90486b5429c6c41ef074d8fe3fbbf178dbdb26
7
+ data.tar.gz: bcc289f532966b861ca869bf059c7fcca9067913e7e434d08db7cef9d92bdb076a96c7e001f031741cf228c58ec8a97e106ed98a0106a4b2a9f442f4e9c68881
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # service-mesh-ruby
2
2
 
3
- This version implements the Service Mesh API Specification v0.4.0.
3
+ This library implements the Service Mesh API Specification v0.5.0.
4
4
 
5
5
  service-mesh-ruby is the Ruby contract for the
6
6
  [Service Mesh API Specification](https://github.com/Paymentbox-com/service-mesh-api).
@@ -24,14 +24,18 @@ 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.
30
34
  - The consumer group is the `consumer_group` member of `Endpoint` and `Subscriber`, defaulting to
31
35
  `nil`. `CONSUMER_GROUP_NONE` is the value for no group.
32
36
  - The reserved metadata prefix `RESERVED_PREFIX` (`Mesh-`).
33
- - The metadata keys the specification defines: `HANDLER_ERROR_KEY`, `TIMEOUT_KEY`, `DEADLINE_KEY`,
34
- `DELIVERY_ATTEMPT_KEY`, and `MESSAGE_ID_KEY`.
37
+ - The metadata keys the specification defines: `HANDLER_ERROR_KEY`, `TIMEOUT_KEY`,
38
+ `DEADLINE_OFFSET_KEY`, `DEADLINE_KEY`, `DELIVERY_ATTEMPT_KEY`, and `MESSAGE_ID_KEY`.
35
39
  - The errors defined by the specification as `ServiceMesh::Error`: `ServiceMesh::KindMismatch`,
36
40
  `ServiceMesh::InvalidTarget`, and `ServiceMesh::NoDeploymentGroup`.
37
41
  - A conformance suite a transport runs against its own `Client` and
@@ -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
 
@@ -26,9 +28,15 @@ module ServiceMesh
26
28
  # caller waits for the reply, as a whole number of milliseconds.
27
29
  TIMEOUT_KEY = "Mesh-Timeout"
28
30
 
31
+ # Set by the requesting transport on a request. The value is how much
32
+ # earlier than the timeout the handler's deadline falls, as a whole number
33
+ # of milliseconds. Absent means 0.
34
+ DEADLINE_OFFSET_KEY = "Mesh-Deadline-Offset"
35
+
29
36
  # Set by the receiving transport on a message it hands to a handler. The
30
37
  # value is when the handler's result stops mattering, in RFC 3339 with
31
- # fractional seconds.
38
+ # fractional seconds. For a request it is the arrival time plus the
39
+ # timeout, minus the offset when the request carries one.
32
40
  DEADLINE_KEY = "Mesh-Deadline"
33
41
 
34
42
  # Set by the receiving transport on a message it hands to a handler. The
@@ -76,6 +84,29 @@ module ServiceMesh
76
84
  def initialize(target:, metadata: {}, payload: "")
77
85
  super(target: target, metadata: metadata.to_h.freeze, payload: payload.to_s.b.freeze)
78
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
79
110
  end
80
111
 
81
112
  # A route target paired with a handler that returns a Message.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ServiceMesh
4
- VERSION = "0.7.1"
4
+ VERSION = "0.9.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: service_mesh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryant Morrill
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2026-11-04 00:00:00.000000000 Z
12
+ date: 2026-12-04 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: