restate-sdk 0.12.0-x86_64-linux → 0.13.0-x86_64-linux
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/Cargo.lock +1 -1
- data/ext/restate_internal/Cargo.toml +1 -1
- data/ext/restate_internal/src/lib.rs +39 -6
- data/lib/restate/3.3/restate_internal.so +0 -0
- data/lib/restate/3.4/restate_internal.so +0 -0
- data/lib/restate/4.0/restate_internal.so +0 -0
- data/lib/restate/config.rb +11 -0
- data/lib/restate/discovery.rb +1 -1
- data/lib/restate/errors.rb +4 -2
- data/lib/restate/server/context.rb +4 -4
- data/lib/restate/version.rb +1 -1
- data/lib/restate/vm.rb +22 -10
- data/lib/restate.rb +7 -1
- data/sig/restate.rbs +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3886f200d09df85267ac44d61ee031dcf7b3c67c19ec36d4588d6ade808dbe6f
|
|
4
|
+
data.tar.gz: f7580ea8952fb87fa37cad385c85bd39491f8ac169b66c3d9338061e7c47d60b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5db2971d531c39c8f93619cc09a9b2c46ca81b7c4f78ad2931c2c3da95c942252bc6c6d7b36b0836afa7abde502492e745e468d470736b6204d88b42fa4ac239
|
|
7
|
+
data.tar.gz: 4af1720520b8fe5107e275a7cea05026c657aa6ae1be26fb0ed17e740e328f6b4bca430e0664b4b012ded7b6ebf1edca43637531a06fb83d19b0026154b85229
|
data/Cargo.lock
CHANGED
|
@@ -129,6 +129,7 @@ struct RbFailure {
|
|
|
129
129
|
code: u16,
|
|
130
130
|
message: String,
|
|
131
131
|
stacktrace: Option<String>,
|
|
132
|
+
metadata: Vec<(String, String)>,
|
|
132
133
|
}
|
|
133
134
|
|
|
134
135
|
impl RbFailure {
|
|
@@ -141,6 +142,17 @@ impl RbFailure {
|
|
|
141
142
|
fn stacktrace(&self) -> Option<&str> {
|
|
142
143
|
self.stacktrace.as_deref()
|
|
143
144
|
}
|
|
145
|
+
fn metadata_array(&self) -> Result<RArray, Error> {
|
|
146
|
+
let ruby = Ruby::get().map_err(|_| Error::new(vm_error_class(), "Ruby not available"))?;
|
|
147
|
+
let ary = ruby.ary_new_capa(self.metadata.len());
|
|
148
|
+
for (k, v) in &self.metadata {
|
|
149
|
+
let pair = ruby.ary_new_capa(2);
|
|
150
|
+
pair.push(ruby.str_new(k))?;
|
|
151
|
+
pair.push(ruby.str_new(v))?;
|
|
152
|
+
ary.push(pair)?;
|
|
153
|
+
}
|
|
154
|
+
Ok(ary)
|
|
155
|
+
}
|
|
144
156
|
}
|
|
145
157
|
|
|
146
158
|
impl From<TerminalFailure> for RbFailure {
|
|
@@ -149,6 +161,7 @@ impl From<TerminalFailure> for RbFailure {
|
|
|
149
161
|
code: f.code,
|
|
150
162
|
message: f.message,
|
|
151
163
|
stacktrace: None,
|
|
164
|
+
metadata: f.metadata,
|
|
152
165
|
}
|
|
153
166
|
}
|
|
154
167
|
}
|
|
@@ -158,7 +171,7 @@ impl From<RbFailure> for TerminalFailure {
|
|
|
158
171
|
TerminalFailure {
|
|
159
172
|
code: f.code,
|
|
160
173
|
message: f.message,
|
|
161
|
-
metadata:
|
|
174
|
+
metadata: f.metadata,
|
|
162
175
|
}
|
|
163
176
|
}
|
|
164
177
|
}
|
|
@@ -929,17 +942,36 @@ fn parse_headers_array(ary: RArray) -> Result<Vec<Header>, Error> {
|
|
|
929
942
|
|
|
930
943
|
// Constructor functions (free functions for use with function! macro)
|
|
931
944
|
|
|
932
|
-
fn rb_failure_new(
|
|
945
|
+
fn rb_failure_new(
|
|
946
|
+
code: u16,
|
|
947
|
+
message: String,
|
|
948
|
+
stacktrace: Value,
|
|
949
|
+
metadata: Value,
|
|
950
|
+
) -> Result<RbFailure, Error> {
|
|
933
951
|
let st = if stacktrace.is_nil() {
|
|
934
952
|
None
|
|
935
953
|
} else {
|
|
936
954
|
Some(String::try_convert(stacktrace).unwrap_or_default())
|
|
937
955
|
};
|
|
938
|
-
|
|
956
|
+
let md = if metadata.is_nil() {
|
|
957
|
+
Vec::new()
|
|
958
|
+
} else {
|
|
959
|
+
let ary = RArray::try_convert(metadata)?;
|
|
960
|
+
let mut out = Vec::with_capacity(ary.len());
|
|
961
|
+
for item in ary.into_iter() {
|
|
962
|
+
let pair = RArray::try_convert(item)?;
|
|
963
|
+
let k: String = pair.entry(0)?;
|
|
964
|
+
let v: String = pair.entry(1)?;
|
|
965
|
+
out.push((k, v));
|
|
966
|
+
}
|
|
967
|
+
out
|
|
968
|
+
};
|
|
969
|
+
Ok(RbFailure {
|
|
939
970
|
code,
|
|
940
971
|
message,
|
|
941
972
|
stacktrace: st,
|
|
942
|
-
|
|
973
|
+
metadata: md,
|
|
974
|
+
})
|
|
943
975
|
}
|
|
944
976
|
|
|
945
977
|
fn rb_exponential_retry_config_new(
|
|
@@ -1002,12 +1034,13 @@ fn init(ruby: &Ruby) -> Result<(), Error> {
|
|
|
1002
1034
|
rh_class.define_method("status_code", method!(RbResponseHead::status_code, 0))?;
|
|
1003
1035
|
rh_class.define_method("headers", method!(RbResponseHead::headers_array, 0))?;
|
|
1004
1036
|
|
|
1005
|
-
// Failure - constructor takes (code, message, stacktrace_or_nil)
|
|
1037
|
+
// Failure - constructor takes (code, message, stacktrace_or_nil, metadata_or_nil)
|
|
1006
1038
|
let failure_class = internal.define_class("Failure", ruby.class_object())?;
|
|
1007
|
-
failure_class.define_singleton_method("new", function!(rb_failure_new,
|
|
1039
|
+
failure_class.define_singleton_method("new", function!(rb_failure_new, 4))?;
|
|
1008
1040
|
failure_class.define_method("code", method!(RbFailure::code, 0))?;
|
|
1009
1041
|
failure_class.define_method("message", method!(RbFailure::message, 0))?;
|
|
1010
1042
|
failure_class.define_method("stacktrace", method!(RbFailure::stacktrace, 0))?;
|
|
1043
|
+
failure_class.define_method("metadata", method!(RbFailure::metadata_array, 0))?;
|
|
1011
1044
|
|
|
1012
1045
|
// Void, Suspended, StateKeys
|
|
1013
1046
|
internal.define_class("Void", ruby.class_object())?;
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/restate/config.rb
CHANGED
|
@@ -20,9 +20,20 @@ module Restate
|
|
|
20
20
|
attr_accessor :admin_url
|
|
21
21
|
|
|
22
22
|
# Default headers sent with every ingress request.
|
|
23
|
+
# Can be a Hash or a callable (Proc/Lambda) returning a Hash.
|
|
24
|
+
# A callable is evaluated each time +Restate.client+ is called,
|
|
25
|
+
# which lets frameworks like Rails inject per-request context
|
|
26
|
+
# (e.g., team ID, shard routing, auth tokens).
|
|
27
|
+
#
|
|
28
|
+
# @example Static headers
|
|
29
|
+
# config.ingress_headers = { "Authorization" => "Bearer tok" }
|
|
30
|
+
#
|
|
31
|
+
# @example Dynamic headers
|
|
32
|
+
# config.ingress_headers = -> { { "X-Team-Id" => Current.team_id } }
|
|
23
33
|
attr_accessor :ingress_headers
|
|
24
34
|
|
|
25
35
|
# Default headers sent with every admin request.
|
|
36
|
+
# Accepts the same static Hash or callable forms as +ingress_headers+.
|
|
26
37
|
attr_accessor :admin_headers
|
|
27
38
|
|
|
28
39
|
def initialize
|
data/lib/restate/discovery.rb
CHANGED
data/lib/restate/errors.rb
CHANGED
|
@@ -6,12 +6,14 @@ module Restate
|
|
|
6
6
|
#
|
|
7
7
|
# @example
|
|
8
8
|
# raise Restate::TerminalError.new('not found', status_code: 404)
|
|
9
|
+
# raise Restate::TerminalError.new('bad input', metadata: { 'field' => 'name' })
|
|
9
10
|
class TerminalError < StandardError
|
|
10
|
-
attr_reader :status_code
|
|
11
|
+
attr_reader :status_code, :metadata
|
|
11
12
|
|
|
12
|
-
def initialize(message = 'Internal Server Error', status_code: 500)
|
|
13
|
+
def initialize(message = 'Internal Server Error', status_code: 500, metadata: nil)
|
|
13
14
|
super(message)
|
|
14
15
|
@status_code = status_code
|
|
16
|
+
@metadata = metadata
|
|
15
17
|
end
|
|
16
18
|
end
|
|
17
19
|
|
|
@@ -50,7 +50,7 @@ module Restate
|
|
|
50
50
|
@vm.sys_write_output_success(out_buffer)
|
|
51
51
|
@vm.sys_end
|
|
52
52
|
rescue TerminalError => e
|
|
53
|
-
failure = Failure.new(code: e.status_code, message: e.message)
|
|
53
|
+
failure = Failure.new(code: e.status_code, message: e.message, metadata: e.metadata)
|
|
54
54
|
@vm.sys_write_output_failure(failure)
|
|
55
55
|
@vm.sys_end
|
|
56
56
|
rescue SuspendedError, InternalError
|
|
@@ -63,7 +63,7 @@ module Restate
|
|
|
63
63
|
handled = false
|
|
64
64
|
while cause
|
|
65
65
|
if cause.is_a?(TerminalError)
|
|
66
|
-
f = Failure.new(code: cause.status_code, message: cause.message)
|
|
66
|
+
f = Failure.new(code: cause.status_code, message: cause.message, metadata: cause.metadata)
|
|
67
67
|
@vm.sys_write_output_failure(f)
|
|
68
68
|
@vm.sys_end
|
|
69
69
|
handled = true
|
|
@@ -472,7 +472,7 @@ module Restate
|
|
|
472
472
|
when NotReady
|
|
473
473
|
raise "Unexpected NotReady for handle #{handle}"
|
|
474
474
|
when Failure
|
|
475
|
-
raise TerminalError.new(result.message, status_code: result.code)
|
|
475
|
+
raise TerminalError.new(result.message, status_code: result.code, metadata: result.metadata)
|
|
476
476
|
else
|
|
477
477
|
block ? yield(result) : result
|
|
478
478
|
end
|
|
@@ -561,7 +561,7 @@ module Restate
|
|
|
561
561
|
buffer = serde.serialize(result)
|
|
562
562
|
@vm.propose_run_completion_success(handle, buffer)
|
|
563
563
|
rescue TerminalError => e
|
|
564
|
-
failure = Failure.new(code: e.status_code, message: e.message)
|
|
564
|
+
failure = Failure.new(code: e.status_code, message: e.message, metadata: e.metadata)
|
|
565
565
|
@vm.propose_run_completion_failure(handle, failure)
|
|
566
566
|
rescue SuspendedError, InternalError
|
|
567
567
|
raise
|
data/lib/restate/version.rb
CHANGED
data/lib/restate/vm.rb
CHANGED
|
@@ -7,14 +7,19 @@ begin
|
|
|
7
7
|
RUBY_VERSION =~ /(\d+\.\d+)/
|
|
8
8
|
require_relative "#{Regexp.last_match(1)}/restate_internal"
|
|
9
9
|
rescue LoadError
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
begin
|
|
11
|
+
# rake compile output (ext.lib_dir = 'lib/restate' in Rakefile)
|
|
12
|
+
require_relative 'restate_internal'
|
|
13
|
+
rescue LoadError
|
|
14
|
+
# gem install from source: extconf.rb builds to lib/restate_internal
|
|
15
|
+
require_relative '../restate_internal'
|
|
16
|
+
end
|
|
12
17
|
end
|
|
13
18
|
|
|
14
19
|
module Restate
|
|
15
20
|
# Ruby-side data types for VM results
|
|
16
21
|
Invocation = Struct.new(:invocation_id, :random_seed, :headers, :input_buffer, :key, keyword_init: true)
|
|
17
|
-
Failure = Struct.new(:code, :message, :stacktrace, keyword_init: true)
|
|
22
|
+
Failure = Struct.new(:code, :message, :stacktrace, :metadata, keyword_init: true)
|
|
18
23
|
|
|
19
24
|
class NotReady; end
|
|
20
25
|
class Suspended; end
|
|
@@ -157,12 +162,12 @@ module Restate
|
|
|
157
162
|
end
|
|
158
163
|
|
|
159
164
|
def propose_run_completion_failure(handle, failure)
|
|
160
|
-
native_failure = Internal::Failure.new(failure.code, failure.message, nil)
|
|
165
|
+
native_failure = Internal::Failure.new(failure.code, failure.message, nil, native_metadata(failure))
|
|
161
166
|
@vm.propose_run_completion_failure(handle, native_failure)
|
|
162
167
|
end
|
|
163
168
|
|
|
164
169
|
def propose_run_completion_transient(handle, failure:, attempt_duration_ms:, config:)
|
|
165
|
-
native_failure = Internal::Failure.new(failure.code, failure.message, failure.stacktrace)
|
|
170
|
+
native_failure = Internal::Failure.new(failure.code, failure.message, failure.stacktrace, nil)
|
|
166
171
|
native_config = Internal::ExponentialRetryConfig.new(
|
|
167
172
|
config.initial_interval, config.max_attempts,
|
|
168
173
|
config.max_duration, config.max_interval,
|
|
@@ -176,7 +181,7 @@ module Restate
|
|
|
176
181
|
end
|
|
177
182
|
|
|
178
183
|
def sys_write_output_failure(failure)
|
|
179
|
-
native_failure = Internal::Failure.new(failure.code, failure.message, nil)
|
|
184
|
+
native_failure = Internal::Failure.new(failure.code, failure.message, nil, native_metadata(failure))
|
|
180
185
|
@vm.sys_write_output_failure(native_failure)
|
|
181
186
|
end
|
|
182
187
|
|
|
@@ -198,7 +203,7 @@ module Restate
|
|
|
198
203
|
end
|
|
199
204
|
|
|
200
205
|
def sys_complete_awakeable_failure(awakeable_id, failure)
|
|
201
|
-
native_failure = Internal::Failure.new(failure.code, failure.message, nil)
|
|
206
|
+
native_failure = Internal::Failure.new(failure.code, failure.message, nil, native_metadata(failure))
|
|
202
207
|
@vm.sys_complete_awakeable_failure(awakeable_id, native_failure)
|
|
203
208
|
end
|
|
204
209
|
|
|
@@ -215,7 +220,7 @@ module Restate
|
|
|
215
220
|
end
|
|
216
221
|
|
|
217
222
|
def sys_complete_promise_failure(key, failure)
|
|
218
|
-
native_failure = Internal::Failure.new(failure.code, failure.message, nil)
|
|
223
|
+
native_failure = Internal::Failure.new(failure.code, failure.message, nil, native_metadata(failure))
|
|
219
224
|
@vm.sys_complete_promise_failure(key, native_failure)
|
|
220
225
|
end
|
|
221
226
|
|
|
@@ -232,12 +237,19 @@ module Restate
|
|
|
232
237
|
end
|
|
233
238
|
|
|
234
239
|
def sys_complete_signal_failure(invocation_id, name, failure)
|
|
235
|
-
native_failure = Internal::Failure.new(failure.code, failure.message, nil)
|
|
240
|
+
native_failure = Internal::Failure.new(failure.code, failure.message, nil, native_metadata(failure))
|
|
236
241
|
@vm.sys_complete_signal_failure(invocation_id, name, native_failure)
|
|
237
242
|
end
|
|
238
243
|
|
|
239
244
|
private
|
|
240
245
|
|
|
246
|
+
def native_metadata(failure)
|
|
247
|
+
md = failure.metadata
|
|
248
|
+
return nil if md.nil? || md.empty?
|
|
249
|
+
|
|
250
|
+
md.map { |k, v| [k.to_s, v.to_s] }
|
|
251
|
+
end
|
|
252
|
+
|
|
241
253
|
def map_do_progress(result)
|
|
242
254
|
case result
|
|
243
255
|
when Internal::Suspended
|
|
@@ -270,7 +282,7 @@ module Restate
|
|
|
270
282
|
# The native layer returns RString for both.
|
|
271
283
|
result
|
|
272
284
|
when Internal::Failure
|
|
273
|
-
Failure.new(code: result.code, message: result.message)
|
|
285
|
+
Failure.new(code: result.code, message: result.message, metadata: result.metadata.to_h)
|
|
274
286
|
when Internal::StateKeys
|
|
275
287
|
result.keys
|
|
276
288
|
else
|
data/lib/restate.rb
CHANGED
|
@@ -76,7 +76,13 @@ module Restate # rubocop:disable Metrics/ModuleLength
|
|
|
76
76
|
def client
|
|
77
77
|
cfg = config
|
|
78
78
|
Client.new(ingress_url: cfg.ingress_url, admin_url: cfg.admin_url,
|
|
79
|
-
ingress_headers: cfg.ingress_headers,
|
|
79
|
+
ingress_headers: resolve_headers(cfg.ingress_headers),
|
|
80
|
+
admin_headers: resolve_headers(cfg.admin_headers))
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# @!visibility private
|
|
84
|
+
def resolve_headers(headers)
|
|
85
|
+
headers.respond_to?(:call) ? headers.call : headers
|
|
80
86
|
end
|
|
81
87
|
|
|
82
88
|
# ── Context accessor (internal) ──
|
data/sig/restate.rbs
CHANGED
|
@@ -69,7 +69,8 @@ module Restate
|
|
|
69
69
|
|
|
70
70
|
class TerminalError < StandardError
|
|
71
71
|
attr_reader status_code: Integer
|
|
72
|
-
|
|
72
|
+
attr_reader metadata: Hash[String, String]?
|
|
73
|
+
def initialize: (?String message, ?status_code: Integer, ?metadata: Hash[String, String]?) -> void
|
|
73
74
|
end
|
|
74
75
|
|
|
75
76
|
class SuspendedError < StandardError
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: restate-sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.13.0
|
|
5
5
|
platform: x86_64-linux
|
|
6
6
|
authors:
|
|
7
7
|
- Restate Developers
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-05-
|
|
11
|
+
date: 2026-05-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: async
|