Module: Restate::Context
- Included in:
- ObjectSharedContext
- Defined in:
- lib/restate/context.rb
Overview
Base context interface for all Restate handlers.
Provides durable execution (run, run_sync), timers (sleep), service-to-service calls, awakeables, and request metadata.
Instance Method Summary collapse
-
#awakeable(serde: JsonSerde) ⇒ Object
Create an awakeable for external callbacks.
-
#cancel_invocation(invocation_id) ⇒ Object
Request cancellation of another invocation.
-
#generic_call(service, handler, arg, key: nil, idempotency_key: nil, headers: nil) ⇒ Object
Durably call a handler using raw bytes (no serialization).
-
#generic_send(service, handler, arg, key: nil, delay: nil, idempotency_key: nil, headers: nil) ⇒ Object
Fire-and-forget send using raw bytes (no serialization).
-
#key ⇒ Object
Returns the key for this virtual object or workflow invocation.
-
#object_call(service, handler, key, arg, idempotency_key: nil, headers: nil, input_serde: NOT_SET, output_serde: NOT_SET) ⇒ Object
Durably call a handler on a Restate virtual object.
-
#object_send(service, handler, key, arg, delay: nil, idempotency_key: nil, headers: nil, input_serde: NOT_SET) ⇒ Object
Fire-and-forget send to a Restate virtual object handler.
-
#reject_awakeable(awakeable_id, message, code: 500) ⇒ Object
Reject an awakeable with a terminal failure.
-
#request ⇒ Object
Returns metadata about the current invocation.
-
#resolve_awakeable(awakeable_id, payload, serde: JsonSerde) ⇒ Object
Resolve an awakeable with a success value.
-
#run(name, serde: JsonSerde, retry_policy: nil, background: false, &action) ⇒ Object
Execute a durable side effect.
-
#run_sync(name, serde: JsonSerde, retry_policy: nil, background: false, &action) ⇒ Object
Convenience shortcut for run(…).await.
-
#service_call(service, handler, arg, key: nil, idempotency_key: nil, headers: nil, input_serde: NOT_SET, output_serde: NOT_SET) ⇒ Object
Durably call a handler on a Restate service.
-
#service_send(service, handler, arg, key: nil, delay: nil, idempotency_key: nil, headers: nil, input_serde: NOT_SET) ⇒ Object
Fire-and-forget send to a Restate service handler.
-
#sleep(seconds) ⇒ Object
Durable timer that survives handler restarts.
-
#wait_any(*futures) ⇒ Object
Wait until any of the given futures completes.
-
#workflow_call(service, handler, key, arg, idempotency_key: nil, headers: nil, input_serde: NOT_SET, output_serde: NOT_SET) ⇒ Object
Durably call a handler on a Restate workflow.
-
#workflow_send(service, handler, key, arg, delay: nil, idempotency_key: nil, headers: nil, input_serde: NOT_SET) ⇒ Object
Fire-and-forget send to a Restate workflow handler.
Instance Method Details
#awakeable(serde: JsonSerde) ⇒ Object
Create an awakeable for external callbacks. Returns [awakeable_id, DurableFuture].
130 |
# File 'lib/restate/context.rb', line 130 def awakeable(serde: JsonSerde); end |
#cancel_invocation(invocation_id) ⇒ Object
Request cancellation of another invocation.
139 |
# File 'lib/restate/context.rb', line 139 def cancel_invocation(invocation_id); end |
#generic_call(service, handler, arg, key: nil, idempotency_key: nil, headers: nil) ⇒ Object
Durably call a handler using raw bytes (no serialization).
123 |
# File 'lib/restate/context.rb', line 123 def generic_call(service, handler, arg, key: nil, idempotency_key: nil, headers: nil); end |
#generic_send(service, handler, arg, key: nil, delay: nil, idempotency_key: nil, headers: nil) ⇒ Object
Fire-and-forget send using raw bytes (no serialization).
126 |
# File 'lib/restate/context.rb', line 126 def generic_send(service, handler, arg, key: nil, delay: nil, idempotency_key: nil, headers: nil); end |
#key ⇒ Object
Returns the key for this virtual object or workflow invocation.
149 |
# File 'lib/restate/context.rb', line 149 def key; end |
#object_call(service, handler, key, arg, idempotency_key: nil, headers: nil, input_serde: NOT_SET, output_serde: NOT_SET) ⇒ Object
Durably call a handler on a Restate virtual object.
103 104 105 |
# File 'lib/restate/context.rb', line 103 def object_call(service, handler, key, arg, idempotency_key: nil, headers: nil, input_serde: NOT_SET, output_serde: NOT_SET) end |
#object_send(service, handler, key, arg, delay: nil, idempotency_key: nil, headers: nil, input_serde: NOT_SET) ⇒ Object
Fire-and-forget send to a Restate virtual object handler.
108 109 110 |
# File 'lib/restate/context.rb', line 108 def object_send(service, handler, key, arg, delay: nil, idempotency_key: nil, headers: nil, input_serde: NOT_SET) end |
#reject_awakeable(awakeable_id, message, code: 500) ⇒ Object
Reject an awakeable with a terminal failure.
136 |
# File 'lib/restate/context.rb', line 136 def reject_awakeable(awakeable_id, , code: 500); end |
#request ⇒ Object
Returns metadata about the current invocation.
146 |
# File 'lib/restate/context.rb', line 146 def request; end |
#resolve_awakeable(awakeable_id, payload, serde: JsonSerde) ⇒ Object
Resolve an awakeable with a success value.
133 |
# File 'lib/restate/context.rb', line 133 def resolve_awakeable(awakeable_id, payload, serde: JsonSerde); end |
#run(name, serde: JsonSerde, retry_policy: nil, background: false, &action) ⇒ Object
Execute a durable side effect. The block runs at most once; the result is journaled and replayed on retries.
Pass background: true to offload the block to a real OS Thread, keeping the fiber event loop responsive for CPU-intensive work.
81 |
# File 'lib/restate/context.rb', line 81 def run(name, serde: JsonSerde, retry_policy: nil, background: false, &action); end |
#run_sync(name, serde: JsonSerde, retry_policy: nil, background: false, &action) ⇒ Object
Convenience shortcut for run(…).await. Returns the result directly. Accepts all the same options as run, including background: true.
85 |
# File 'lib/restate/context.rb', line 85 def run_sync(name, serde: JsonSerde, retry_policy: nil, background: false, &action); end |
#service_call(service, handler, arg, key: nil, idempotency_key: nil, headers: nil, input_serde: NOT_SET, output_serde: NOT_SET) ⇒ Object
Durably call a handler on a Restate service.
93 94 95 |
# File 'lib/restate/context.rb', line 93 def service_call(service, handler, arg, key: nil, idempotency_key: nil, headers: nil, input_serde: NOT_SET, output_serde: NOT_SET) end |
#service_send(service, handler, arg, key: nil, delay: nil, idempotency_key: nil, headers: nil, input_serde: NOT_SET) ⇒ Object
Fire-and-forget send to a Restate service handler.
98 99 100 |
# File 'lib/restate/context.rb', line 98 def service_send(service, handler, arg, key: nil, delay: nil, idempotency_key: nil, headers: nil, input_serde: NOT_SET) end |
#sleep(seconds) ⇒ Object
Durable timer that survives handler restarts.
88 89 90 |
# File 'lib/restate/context.rb', line 88 def sleep(seconds) # rubocop:disable Lint/UnusedMethodArgument Kernel.raise NotImplementedError end |
#wait_any(*futures) ⇒ Object
Wait until any of the given futures completes. Returns [completed, remaining].
143 |
# File 'lib/restate/context.rb', line 143 def wait_any(*futures); end |
#workflow_call(service, handler, key, arg, idempotency_key: nil, headers: nil, input_serde: NOT_SET, output_serde: NOT_SET) ⇒ Object
Durably call a handler on a Restate workflow.
113 114 115 |
# File 'lib/restate/context.rb', line 113 def workflow_call(service, handler, key, arg, idempotency_key: nil, headers: nil, input_serde: NOT_SET, output_serde: NOT_SET) end |
#workflow_send(service, handler, key, arg, delay: nil, idempotency_key: nil, headers: nil, input_serde: NOT_SET) ⇒ Object
Fire-and-forget send to a Restate workflow handler.
118 119 120 |
# File 'lib/restate/context.rb', line 118 def workflow_send(service, handler, key, arg, delay: nil, idempotency_key: nil, headers: nil, input_serde: NOT_SET) end |