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_progress(handles) ⇒ Object
- #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) ⇒ 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_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) ⇒ Object
- #sys_set_state(name, value) ⇒ 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.
55 56 57 |
# File 'lib/restate/vm.rb', line 55 def initialize(headers) @vm = Internal::VM.new(headers) end |
Instance Method Details
#do_progress(handles) ⇒ Object
88 89 90 91 92 93 |
# File 'lib/restate/vm.rb', line 88 def do_progress(handles) result = @vm.do_progress(handles) map_do_progress(result) rescue Internal::VMError => e e end |
#get_response_head ⇒ Object
59 60 61 62 |
# File 'lib/restate/vm.rb', line 59 def get_response_head result = @vm.get_response_head [result.status_code, result.headers] end |
#is_completed(handle) ⇒ Object
84 85 86 |
# File 'lib/restate/vm.rb', line 84 def is_completed(handle) @vm.is_completed(handle) end |
#is_ready_to_execute ⇒ Object
80 81 82 |
# File 'lib/restate/vm.rb', line 80 def is_ready_to_execute @vm.is_ready_to_execute end |
#is_replaying ⇒ Object
187 188 189 |
# File 'lib/restate/vm.rb', line 187 def @vm. end |
#notify_error(error, stacktrace = nil) ⇒ Object
72 73 74 |
# File 'lib/restate/vm.rb', line 72 def notify_error(error, stacktrace = nil) @vm.notify_error(error, stacktrace) end |
#notify_input(buf) ⇒ Object
64 65 66 |
# File 'lib/restate/vm.rb', line 64 def notify_input(buf) @vm.notify_input(buf) end |
#notify_input_closed ⇒ Object
68 69 70 |
# File 'lib/restate/vm.rb', line 68 def notify_input_closed @vm.notify_input_closed end |
#propose_run_completion_failure(handle, failure) ⇒ Object
159 160 161 162 |
# File 'lib/restate/vm.rb', line 159 def propose_run_completion_failure(handle, failure) native_failure = Internal::Failure.new(failure.code, failure., nil) @vm.propose_run_completion_failure(handle, native_failure) end |
#propose_run_completion_success(handle, output) ⇒ Object
155 156 157 |
# File 'lib/restate/vm.rb', line 155 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
164 165 166 167 168 169 170 171 172 |
# File 'lib/restate/vm.rb', line 164 def propose_run_completion_transient(handle, failure:, attempt_duration_ms:, config:) native_failure = Internal::Failure.new(failure.code, failure., failure.stacktrace) 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)]
192 193 194 |
# File 'lib/restate/vm.rb', line 192 def sys_awakeable @vm.sys_awakeable end |
#sys_call(service:, handler:, parameter:, key: nil, idempotency_key: nil, headers: nil) ⇒ Object
139 140 141 142 143 |
# File 'lib/restate/vm.rb', line 139 def sys_call(service:, handler:, parameter:, key: nil, idempotency_key: nil, headers: nil) # Rust side expects 6 args: (service, handler, buffer, key_or_nil, idem_key_or_nil, headers_or_nil) hdr_array = headers&.map { |k, v| [k, v] } @vm.sys_call(service, handler, parameter, key, idempotency_key, hdr_array) end |
#sys_cancel_invocation(invocation_id) ⇒ Object
222 223 224 |
# File 'lib/restate/vm.rb', line 222 def sys_cancel_invocation(invocation_id) @vm.sys_cancel_invocation(invocation_id) end |
#sys_clear_all_state ⇒ Object
130 131 132 |
# File 'lib/restate/vm.rb', line 130 def sys_clear_all_state @vm.sys_clear_all_state end |
#sys_clear_state(name) ⇒ Object
126 127 128 |
# File 'lib/restate/vm.rb', line 126 def sys_clear_state(name) @vm.sys_clear_state(name) end |
#sys_complete_awakeable_failure(awakeable_id, failure) ⇒ Object
200 201 202 203 |
# File 'lib/restate/vm.rb', line 200 def sys_complete_awakeable_failure(awakeable_id, failure) native_failure = Internal::Failure.new(failure.code, failure., nil) @vm.sys_complete_awakeable_failure(awakeable_id, native_failure) end |
#sys_complete_awakeable_success(awakeable_id, value) ⇒ Object
196 197 198 |
# File 'lib/restate/vm.rb', line 196 def sys_complete_awakeable_success(awakeable_id, value) @vm.sys_complete_awakeable_success(awakeable_id, value) end |
#sys_complete_promise_failure(key, failure) ⇒ Object
217 218 219 220 |
# File 'lib/restate/vm.rb', line 217 def sys_complete_promise_failure(key, failure) native_failure = Internal::Failure.new(failure.code, failure., nil) @vm.sys_complete_promise_failure(key, native_failure) end |
#sys_complete_promise_success(key, value) ⇒ Object
213 214 215 |
# File 'lib/restate/vm.rb', line 213 def sys_complete_promise_success(key, value) @vm.sys_complete_promise_success(key, value) end |
#sys_end ⇒ Object
183 184 185 |
# File 'lib/restate/vm.rb', line 183 def sys_end @vm.sys_end end |
#sys_get_promise(key) ⇒ Object
205 206 207 |
# File 'lib/restate/vm.rb', line 205 def sys_get_promise(key) @vm.sys_get_promise(key) end |
#sys_get_state(name) ⇒ Object
114 115 116 |
# File 'lib/restate/vm.rb', line 114 def sys_get_state(name) @vm.sys_get_state(name) end |
#sys_get_state_keys ⇒ Object
118 119 120 |
# File 'lib/restate/vm.rb', line 118 def sys_get_state_keys @vm.sys_get_state_keys end |
#sys_input ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/restate/vm.rb', line 102 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 ) end |
#sys_peek_promise(key) ⇒ Object
209 210 211 |
# File 'lib/restate/vm.rb', line 209 def sys_peek_promise(key) @vm.sys_peek_promise(key) end |
#sys_run(name) ⇒ Object
151 152 153 |
# File 'lib/restate/vm.rb', line 151 def sys_run(name) @vm.sys_run(name) end |
#sys_send(service:, handler:, parameter:, key: nil, delay: nil, idempotency_key: nil, headers: nil) ⇒ Object
145 146 147 148 149 |
# File 'lib/restate/vm.rb', line 145 def sys_send(service:, handler:, parameter:, key: nil, delay: nil, idempotency_key: nil, headers: nil) # Rust side expects 7 args hdr_array = headers&.map { |k, v| [k, v] } @vm.sys_send(service, handler, parameter, key, delay, idempotency_key, hdr_array) end |
#sys_set_state(name, value) ⇒ Object
122 123 124 |
# File 'lib/restate/vm.rb', line 122 def sys_set_state(name, value) @vm.sys_set_state(name, value) end |
#sys_sleep(millis, name = nil) ⇒ Object
134 135 136 137 |
# File 'lib/restate/vm.rb', line 134 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
178 179 180 181 |
# File 'lib/restate/vm.rb', line 178 def sys_write_output_failure(failure) native_failure = Internal::Failure.new(failure.code, failure., nil) @vm.sys_write_output_failure(native_failure) end |
#sys_write_output_success(output) ⇒ Object
174 175 176 |
# File 'lib/restate/vm.rb', line 174 def sys_write_output_success(output) @vm.sys_write_output_success(output) end |
#take_notification(handle) ⇒ Object
95 96 97 98 99 100 |
# File 'lib/restate/vm.rb', line 95 def take_notification(handle) result = @vm.take_notification(handle) map_notification(result) rescue Internal::VMError => e e end |
#take_output ⇒ Object
76 77 78 |
# File 'lib/restate/vm.rb', line 76 def take_output @vm.take_output end |