Class: Restate::VMWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/restate/vm.rb

Overview

Wraps the native Restate::Internal::VM, mapping native types to Ruby types.

Instance Method Summary collapse

Constructor Details

#initialize(headers) ⇒ VMWrapper

Returns a new instance of VMWrapper.



60
61
62
# File 'lib/restate/vm.rb', line 60

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.



97
98
99
100
101
102
# File 'lib/restate/vm.rb', line 97

def do_await(future)
  result = @vm.do_await(future)
  map_do_progress(result)
rescue Internal::VMError => e
  e
end

#get_response_headObject



64
65
66
67
# File 'lib/restate/vm.rb', line 64

def get_response_head
  result = @vm.get_response_head
  [result.status_code, result.headers]
end

#is_completed(handle) ⇒ Object



89
90
91
# File 'lib/restate/vm.rb', line 89

def is_completed(handle)
  @vm.is_completed(handle)
end

#is_ready_to_executeObject



85
86
87
# File 'lib/restate/vm.rb', line 85

def is_ready_to_execute
  @vm.is_ready_to_execute
end

#is_replayingObject



196
197
198
# File 'lib/restate/vm.rb', line 196

def is_replaying
  @vm.is_replaying
end

#notify_error(error, stacktrace = nil) ⇒ Object



77
78
79
# File 'lib/restate/vm.rb', line 77

def notify_error(error, stacktrace = nil)
  @vm.notify_error(error, stacktrace)
end

#notify_input(buf) ⇒ Object



69
70
71
# File 'lib/restate/vm.rb', line 69

def notify_input(buf)
  @vm.notify_input(buf)
end

#notify_input_closedObject



73
74
75
# File 'lib/restate/vm.rb', line 73

def notify_input_closed
  @vm.notify_input_closed
end

#propose_run_completion_failure(handle, failure) ⇒ Object



168
169
170
171
# File 'lib/restate/vm.rb', line 168

def propose_run_completion_failure(handle, failure)
  native_failure = Internal::Failure.new(failure.code, failure.message, nil, (failure))
  @vm.propose_run_completion_failure(handle, native_failure)
end

#propose_run_completion_success(handle, output) ⇒ Object



164
165
166
# File 'lib/restate/vm.rb', line 164

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



173
174
175
176
177
178
179
180
181
# File 'lib/restate/vm.rb', line 173

def propose_run_completion_transient(handle, failure:, attempt_duration_ms:, config:)
  native_failure = Internal::Failure.new(failure.code, failure.message, 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_awakeableObject

Returns [awakeable_id (String), notification_handle (Integer)]



201
202
203
# File 'lib/restate/vm.rb', line 201

def sys_awakeable
  @vm.sys_awakeable
end

#sys_call(service:, handler:, parameter:, key: nil, idempotency_key: nil, headers: nil) ⇒ Object



148
149
150
151
152
# File 'lib/restate/vm.rb', line 148

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



231
232
233
# File 'lib/restate/vm.rb', line 231

def sys_cancel_invocation(invocation_id)
  @vm.sys_cancel_invocation(invocation_id)
end

#sys_clear_all_stateObject



139
140
141
# File 'lib/restate/vm.rb', line 139

def sys_clear_all_state
  @vm.sys_clear_all_state
end

#sys_clear_state(name) ⇒ Object



135
136
137
# File 'lib/restate/vm.rb', line 135

def sys_clear_state(name)
  @vm.sys_clear_state(name)
end

#sys_complete_awakeable_failure(awakeable_id, failure) ⇒ Object



209
210
211
212
# File 'lib/restate/vm.rb', line 209

def sys_complete_awakeable_failure(awakeable_id, failure)
  native_failure = Internal::Failure.new(failure.code, failure.message, nil, (failure))
  @vm.sys_complete_awakeable_failure(awakeable_id, native_failure)
end

#sys_complete_awakeable_success(awakeable_id, value) ⇒ Object



205
206
207
# File 'lib/restate/vm.rb', line 205

def sys_complete_awakeable_success(awakeable_id, value)
  @vm.sys_complete_awakeable_success(awakeable_id, value)
end

#sys_complete_promise_failure(key, failure) ⇒ Object



226
227
228
229
# File 'lib/restate/vm.rb', line 226

def sys_complete_promise_failure(key, failure)
  native_failure = Internal::Failure.new(failure.code, failure.message, nil, (failure))
  @vm.sys_complete_promise_failure(key, native_failure)
end

#sys_complete_promise_success(key, value) ⇒ Object



222
223
224
# File 'lib/restate/vm.rb', line 222

def sys_complete_promise_success(key, value)
  @vm.sys_complete_promise_success(key, value)
end

#sys_complete_signal_failure(invocation_id, name, failure) ⇒ Object



243
244
245
246
# File 'lib/restate/vm.rb', line 243

def sys_complete_signal_failure(invocation_id, name, failure)
  native_failure = Internal::Failure.new(failure.code, failure.message, nil, (failure))
  @vm.sys_complete_signal_failure(invocation_id, name, native_failure)
end

#sys_complete_signal_success(invocation_id, name, value) ⇒ Object



239
240
241
# File 'lib/restate/vm.rb', line 239

def sys_complete_signal_success(invocation_id, name, value)
  @vm.sys_complete_signal_success(invocation_id, name, value)
end

#sys_endObject



192
193
194
# File 'lib/restate/vm.rb', line 192

def sys_end
  @vm.sys_end
end

#sys_get_promise(key) ⇒ Object



214
215
216
# File 'lib/restate/vm.rb', line 214

def sys_get_promise(key)
  @vm.sys_get_promise(key)
end

#sys_get_state(name) ⇒ Object



123
124
125
# File 'lib/restate/vm.rb', line 123

def sys_get_state(name)
  @vm.sys_get_state(name)
end

#sys_get_state_keysObject



127
128
129
# File 'lib/restate/vm.rb', line 127

def sys_get_state_keys
  @vm.sys_get_state_keys
end

#sys_inputObject



111
112
113
114
115
116
117
118
119
120
121
# File 'lib/restate/vm.rb', line 111

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



218
219
220
# File 'lib/restate/vm.rb', line 218

def sys_peek_promise(key)
  @vm.sys_peek_promise(key)
end

#sys_run(name) ⇒ Object



160
161
162
# File 'lib/restate/vm.rb', line 160

def sys_run(name)
  @vm.sys_run(name)
end

#sys_send(service:, handler:, parameter:, key: nil, delay: nil, idempotency_key: nil, headers: nil) ⇒ Object



154
155
156
157
158
# File 'lib/restate/vm.rb', line 154

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



131
132
133
# File 'lib/restate/vm.rb', line 131

def sys_set_state(name, value)
  @vm.sys_set_state(name, value)
end

#sys_signal(name) ⇒ Object



235
236
237
# File 'lib/restate/vm.rb', line 235

def sys_signal(name)
  @vm.sys_signal(name)
end

#sys_sleep(millis, name = nil) ⇒ Object



143
144
145
146
# File 'lib/restate/vm.rb', line 143

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



187
188
189
190
# File 'lib/restate/vm.rb', line 187

def sys_write_output_failure(failure)
  native_failure = Internal::Failure.new(failure.code, failure.message, nil, (failure))
  @vm.sys_write_output_failure(native_failure)
end

#sys_write_output_success(output) ⇒ Object



183
184
185
# File 'lib/restate/vm.rb', line 183

def sys_write_output_success(output)
  @vm.sys_write_output_success(output)
end

#take_notification(handle) ⇒ Object



104
105
106
107
108
109
# File 'lib/restate/vm.rb', line 104

def take_notification(handle)
  result = @vm.take_notification(handle)
  map_notification(result)
rescue Internal::VMError => e
  e
end

#take_outputObject



81
82
83
# File 'lib/restate/vm.rb', line 81

def take_output
  @vm.take_output
end