Class: Restate::VMWrapper
- Inherits:
-
Object
- Object
- Restate::VMWrapper
- Defined in:
- lib/restate/vm.rb
Overview
Wraps the native Restate::Internal::VM, mapping native types to Ruby types.
Instance Method Summary collapse
-
#do_await(future) ⇒ Object
Drive the VM forward against an
UnresolvedFuturetree. - #get_response_head ⇒ Object
-
#initialize(headers) ⇒ VMWrapper
constructor
A new instance of VMWrapper.
- #is_completed(handle) ⇒ Object
- #is_ready_to_execute ⇒ Object
- #is_replaying ⇒ Object
- #notify_error(error, stacktrace = nil) ⇒ Object
- #notify_input(buf) ⇒ Object
- #notify_input_closed ⇒ Object
- #propose_run_completion_failure(handle, failure) ⇒ Object
- #propose_run_completion_success(handle, output) ⇒ Object
- #propose_run_completion_transient(handle, failure:, attempt_duration_ms:, config:) ⇒ Object
-
#sys_awakeable ⇒ Object
Returns [awakeable_id (String), notification_handle (Integer)].
- #sys_call(service:, handler:, parameter:, key: nil, idempotency_key: nil, headers: nil, scope: nil, limit_key: nil) ⇒ Object
- #sys_cancel_invocation(invocation_id) ⇒ Object
- #sys_clear_all_state ⇒ Object
- #sys_clear_state(name) ⇒ Object
- #sys_complete_awakeable_failure(awakeable_id, failure) ⇒ Object
- #sys_complete_awakeable_success(awakeable_id, value) ⇒ Object
- #sys_complete_promise_failure(key, failure) ⇒ Object
- #sys_complete_promise_success(key, value) ⇒ Object
- #sys_complete_signal_failure(invocation_id, name, failure) ⇒ Object
- #sys_complete_signal_success(invocation_id, name, value) ⇒ Object
- #sys_end ⇒ Object
- #sys_get_promise(key) ⇒ Object
- #sys_get_state(name) ⇒ Object
- #sys_get_state_keys ⇒ Object
- #sys_input ⇒ Object
- #sys_peek_promise(key) ⇒ Object
- #sys_run(name) ⇒ Object
- #sys_send(service:, handler:, parameter:, key: nil, delay: nil, idempotency_key: nil, headers: nil, scope: nil, limit_key: nil) ⇒ Object
- #sys_set_state(name, value) ⇒ Object
- #sys_signal(name) ⇒ Object
- #sys_sleep(millis, name = nil) ⇒ Object
- #sys_write_output_failure(failure) ⇒ Object
- #sys_write_output_success(output) ⇒ Object
- #take_notification(handle) ⇒ Object
- #take_output ⇒ Object
Constructor Details
#initialize(headers) ⇒ VMWrapper
Returns a new instance of VMWrapper.
61 62 63 |
# File 'lib/restate/vm.rb', line 61 def initialize(headers) @vm = Internal::VM.new(headers) end |
Instance Method Details
#do_await(future) ⇒ Object
Drive the VM forward against an UnresolvedFuture tree. future is either
an Integer handle (Single leaf) or a [tag_symbol, [children...]] pair
(combinator node). See the Rust-side parse_unresolved_future for the
supported tags.
98 99 100 101 102 103 |
# File 'lib/restate/vm.rb', line 98 def do_await(future) result = @vm.do_await(future) map_do_progress(result) rescue Internal::VMError => e e end |
#get_response_head ⇒ Object
65 66 67 68 |
# File 'lib/restate/vm.rb', line 65 def get_response_head result = @vm.get_response_head [result.status_code, result.headers] end |
#is_completed(handle) ⇒ Object
90 91 92 |
# File 'lib/restate/vm.rb', line 90 def is_completed(handle) @vm.is_completed(handle) end |
#is_ready_to_execute ⇒ Object
86 87 88 |
# File 'lib/restate/vm.rb', line 86 def is_ready_to_execute @vm.is_ready_to_execute end |
#is_replaying ⇒ Object
203 204 205 |
# File 'lib/restate/vm.rb', line 203 def @vm. end |
#notify_error(error, stacktrace = nil) ⇒ Object
78 79 80 |
# File 'lib/restate/vm.rb', line 78 def notify_error(error, stacktrace = nil) @vm.notify_error(error, stacktrace) end |
#notify_input(buf) ⇒ Object
70 71 72 |
# File 'lib/restate/vm.rb', line 70 def notify_input(buf) @vm.notify_input(buf) end |
#notify_input_closed ⇒ Object
74 75 76 |
# File 'lib/restate/vm.rb', line 74 def notify_input_closed @vm.notify_input_closed end |
#propose_run_completion_failure(handle, failure) ⇒ Object
175 176 177 178 |
# File 'lib/restate/vm.rb', line 175 def propose_run_completion_failure(handle, failure) native_failure = Internal::Failure.new(failure.code, failure., nil, (failure)) @vm.propose_run_completion_failure(handle, native_failure) end |
#propose_run_completion_success(handle, output) ⇒ Object
171 172 173 |
# File 'lib/restate/vm.rb', line 171 def propose_run_completion_success(handle, output) @vm.propose_run_completion_success(handle, output) end |
#propose_run_completion_transient(handle, failure:, attempt_duration_ms:, config:) ⇒ Object
180 181 182 183 184 185 186 187 188 |
# File 'lib/restate/vm.rb', line 180 def propose_run_completion_transient(handle, failure:, attempt_duration_ms:, config:) native_failure = Internal::Failure.new(failure.code, failure., failure.stacktrace, nil) native_config = Internal::ExponentialRetryConfig.new( config.initial_interval, config.max_attempts, config.max_duration, config.max_interval, config.interval_factor ) @vm.propose_run_completion_failure_transient(handle, native_failure, attempt_duration_ms, native_config) end |
#sys_awakeable ⇒ Object
Returns [awakeable_id (String), notification_handle (Integer)]
208 209 210 |
# File 'lib/restate/vm.rb', line 208 def sys_awakeable @vm.sys_awakeable end |
#sys_call(service:, handler:, parameter:, key: nil, idempotency_key: nil, headers: nil, scope: nil, limit_key: nil) ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/restate/vm.rb', line 152 def sys_call(service:, handler:, parameter:, key: nil, idempotency_key: nil, headers: nil, scope: nil, limit_key: nil) # Rust side expects 8 args: # (service, handler, buffer, key_or_nil, idem_key_or_nil, headers_or_nil, scope_or_nil, limit_key_or_nil) hdr_array = headers&.map { |k, v| [k, v] } @vm.sys_call(service, handler, parameter, key, idempotency_key, hdr_array, scope, limit_key) end |
#sys_cancel_invocation(invocation_id) ⇒ Object
238 239 240 |
# File 'lib/restate/vm.rb', line 238 def sys_cancel_invocation(invocation_id) @vm.sys_cancel_invocation(invocation_id) end |
#sys_clear_all_state ⇒ Object
143 144 145 |
# File 'lib/restate/vm.rb', line 143 def sys_clear_all_state @vm.sys_clear_all_state end |
#sys_clear_state(name) ⇒ Object
139 140 141 |
# File 'lib/restate/vm.rb', line 139 def sys_clear_state(name) @vm.sys_clear_state(name) end |
#sys_complete_awakeable_failure(awakeable_id, failure) ⇒ Object
216 217 218 219 |
# File 'lib/restate/vm.rb', line 216 def sys_complete_awakeable_failure(awakeable_id, failure) native_failure = Internal::Failure.new(failure.code, failure., nil, (failure)) @vm.sys_complete_awakeable_failure(awakeable_id, native_failure) end |
#sys_complete_awakeable_success(awakeable_id, value) ⇒ Object
212 213 214 |
# File 'lib/restate/vm.rb', line 212 def sys_complete_awakeable_success(awakeable_id, value) @vm.sys_complete_awakeable_success(awakeable_id, value) end |
#sys_complete_promise_failure(key, failure) ⇒ Object
233 234 235 236 |
# File 'lib/restate/vm.rb', line 233 def sys_complete_promise_failure(key, failure) native_failure = Internal::Failure.new(failure.code, failure., nil, (failure)) @vm.sys_complete_promise_failure(key, native_failure) end |
#sys_complete_promise_success(key, value) ⇒ Object
229 230 231 |
# File 'lib/restate/vm.rb', line 229 def sys_complete_promise_success(key, value) @vm.sys_complete_promise_success(key, value) end |
#sys_complete_signal_failure(invocation_id, name, failure) ⇒ Object
250 251 252 253 |
# File 'lib/restate/vm.rb', line 250 def sys_complete_signal_failure(invocation_id, name, failure) native_failure = Internal::Failure.new(failure.code, failure., nil, (failure)) @vm.sys_complete_signal_failure(invocation_id, name, native_failure) end |
#sys_complete_signal_success(invocation_id, name, value) ⇒ Object
246 247 248 |
# File 'lib/restate/vm.rb', line 246 def sys_complete_signal_success(invocation_id, name, value) @vm.sys_complete_signal_success(invocation_id, name, value) end |
#sys_end ⇒ Object
199 200 201 |
# File 'lib/restate/vm.rb', line 199 def sys_end @vm.sys_end end |
#sys_get_promise(key) ⇒ Object
221 222 223 |
# File 'lib/restate/vm.rb', line 221 def sys_get_promise(key) @vm.sys_get_promise(key) end |
#sys_get_state(name) ⇒ Object
127 128 129 |
# File 'lib/restate/vm.rb', line 127 def sys_get_state(name) @vm.sys_get_state(name) end |
#sys_get_state_keys ⇒ Object
131 132 133 |
# File 'lib/restate/vm.rb', line 131 def sys_get_state_keys @vm.sys_get_state_keys end |
#sys_input ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/restate/vm.rb', line 112 def sys_input inp = @vm.sys_input headers = inp.headers.map { |h| [h.key, h.value] } Invocation.new( invocation_id: inp.invocation_id, random_seed: inp.random_seed, headers: headers, input_buffer: inp.input.b, key: inp.key, scope: inp.scope, limit_key: inp.limit_key, idempotency_key: inp.idempotency_key ) end |
#sys_peek_promise(key) ⇒ Object
225 226 227 |
# File 'lib/restate/vm.rb', line 225 def sys_peek_promise(key) @vm.sys_peek_promise(key) end |
#sys_run(name) ⇒ Object
167 168 169 |
# File 'lib/restate/vm.rb', line 167 def sys_run(name) @vm.sys_run(name) end |
#sys_send(service:, handler:, parameter:, key: nil, delay: nil, idempotency_key: nil, headers: nil, scope: nil, limit_key: nil) ⇒ Object
160 161 162 163 164 165 |
# File 'lib/restate/vm.rb', line 160 def sys_send(service:, handler:, parameter:, key: nil, delay: nil, idempotency_key: nil, headers: nil, scope: nil, limit_key: nil) # Rust side expects 9 args hdr_array = headers&.map { |k, v| [k, v] } @vm.sys_send(service, handler, parameter, key, delay, idempotency_key, hdr_array, scope, limit_key) end |
#sys_set_state(name, value) ⇒ Object
135 136 137 |
# File 'lib/restate/vm.rb', line 135 def sys_set_state(name, value) @vm.sys_set_state(name, value) end |
#sys_signal(name) ⇒ Object
242 243 244 |
# File 'lib/restate/vm.rb', line 242 def sys_signal(name) @vm.sys_signal(name) end |
#sys_sleep(millis, name = nil) ⇒ Object
147 148 149 150 |
# File 'lib/restate/vm.rb', line 147 def sys_sleep(millis, name = nil) # Rust side always expects 2 args: (millis, name_or_nil) @vm.sys_sleep(millis, name) end |
#sys_write_output_failure(failure) ⇒ Object
194 195 196 197 |
# File 'lib/restate/vm.rb', line 194 def sys_write_output_failure(failure) native_failure = Internal::Failure.new(failure.code, failure., nil, (failure)) @vm.sys_write_output_failure(native_failure) end |
#sys_write_output_success(output) ⇒ Object
190 191 192 |
# File 'lib/restate/vm.rb', line 190 def sys_write_output_success(output) @vm.sys_write_output_success(output) end |
#take_notification(handle) ⇒ Object
105 106 107 108 109 110 |
# File 'lib/restate/vm.rb', line 105 def take_notification(handle) result = @vm.take_notification(handle) map_notification(result) rescue Internal::VMError => e e end |
#take_output ⇒ Object
82 83 84 |
# File 'lib/restate/vm.rb', line 82 def take_output @vm.take_output end |