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, scope: nil, limit_key: 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, scope: nil, limit_key: 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.
-
#reject_signal(invocation_id, name, message, code: 500) ⇒ Object
Send a terminal failure to a named signal on another invocation.
-
#request ⇒ Object
Returns metadata about the current invocation.
-
#resolve_awakeable(awakeable_id, payload, serde: JsonSerde) ⇒ Object
Resolve an awakeable with a success value.
-
#resolve_signal(invocation_id, name, payload, serde: JsonSerde) ⇒ Object
Send a success value to a named signal on another invocation.
-
#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. -
#scope(scope) ⇒ ScopedContext
Returns a
ScopedContextthat routes all outgoing calls within the given scope. -
#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.
-
#signal(name, serde: JsonSerde) ⇒ Object
Wait for a named signal addressed to this invocation.
-
#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].
164 |
# File 'lib/restate/context.rb', line 164 def awakeable(serde: JsonSerde); end |
#cancel_invocation(invocation_id) ⇒ Object
Request cancellation of another invocation.
185 |
# File 'lib/restate/context.rb', line 185 def cancel_invocation(invocation_id); end |
#generic_call(service, handler, arg, key: nil, idempotency_key: nil, headers: nil, scope: nil, limit_key: nil) ⇒ Object
Durably call a handler using raw bytes (no serialization).
130 131 132 |
# File 'lib/restate/context.rb', line 130 def generic_call(service, handler, arg, key: nil, idempotency_key: nil, headers: nil, scope: nil, limit_key: nil) end |
#generic_send(service, handler, arg, key: nil, delay: nil, idempotency_key: nil, headers: nil, scope: nil, limit_key: nil) ⇒ Object
Fire-and-forget send using raw bytes (no serialization).
135 136 137 |
# File 'lib/restate/context.rb', line 135 def generic_send(service, handler, arg, key: nil, delay: nil, idempotency_key: nil, headers: nil, scope: nil, limit_key: nil) end |
#key ⇒ Object
Returns the key for this virtual object or workflow invocation.
195 |
# File 'lib/restate/context.rb', line 195 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.
110 111 112 |
# File 'lib/restate/context.rb', line 110 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.
115 116 117 |
# File 'lib/restate/context.rb', line 115 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.
170 |
# File 'lib/restate/context.rb', line 170 def reject_awakeable(awakeable_id, , code: 500); end |
#reject_signal(invocation_id, name, message, code: 500) ⇒ Object
Send a terminal failure to a named signal on another invocation.
182 |
# File 'lib/restate/context.rb', line 182 def reject_signal(invocation_id, name, , code: 500); end |
#request ⇒ Object
Returns metadata about the current invocation.
192 |
# File 'lib/restate/context.rb', line 192 def request; end |
#resolve_awakeable(awakeable_id, payload, serde: JsonSerde) ⇒ Object
Resolve an awakeable with a success value.
167 |
# File 'lib/restate/context.rb', line 167 def resolve_awakeable(awakeable_id, payload, serde: JsonSerde); end |
#resolve_signal(invocation_id, name, payload, serde: JsonSerde) ⇒ Object
Send a success value to a named signal on another invocation.
179 |
# File 'lib/restate/context.rb', line 179 def resolve_signal(invocation_id, name, 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.
88 |
# File 'lib/restate/context.rb', line 88 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.
92 |
# File 'lib/restate/context.rb', line 92 def run_sync(name, serde: JsonSerde, retry_policy: nil, background: false, &action); end |
#scope(scope) ⇒ ScopedContext
Returns a ScopedContext that routes all outgoing calls within the given scope.
NOTE: This API is in preview and is not enabled by default. To use it in
restate-server 1.7, enable the flow control and protocol v7 experimental
features via RESTATE_EXPERIMENTAL_ENABLE_PROTOCOL_V7=true and
RESTATE_EXPERIMENTAL_ENABLE_VQUEUES=true. These can be enabled only on new
clusters. If they aren't enabled, the call fails with a retryable error and
keeps retrying until they are.
A scope is a sub-grouping of resources (invocations, workflow instances,
concurrency limits) within the Restate cluster. It becomes part of the target
identity tuple and contributes to the partition key, so all resources in a
scope get co-located by the restate-server. Omitting the scope (i.e. using the
regular service_call / workflow_call methods) is equivalent to calling
with no scope, which is the existing behavior.
The scope must consist only of [a-zA-Z0-9_.-] characters, 1 <= length <= 36.
160 |
# File 'lib/restate/context.rb', line 160 def scope(scope); 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.
100 101 102 |
# File 'lib/restate/context.rb', line 100 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.
105 106 107 |
# File 'lib/restate/context.rb', line 105 def service_send(service, handler, arg, key: nil, delay: nil, idempotency_key: nil, headers: nil, input_serde: NOT_SET) end |
#signal(name, serde: JsonSerde) ⇒ Object
Wait for a named signal addressed to this invocation.
Returns a DurableFuture that resolves once another invocation calls
resolve_signal or reject_signal with the same name targeting this
invocation's id.
176 |
# File 'lib/restate/context.rb', line 176 def signal(name, serde: JsonSerde); end |
#sleep(seconds) ⇒ Object
Durable timer that survives handler restarts.
95 96 97 |
# File 'lib/restate/context.rb', line 95 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].
189 |
# File 'lib/restate/context.rb', line 189 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.
120 121 122 |
# File 'lib/restate/context.rb', line 120 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.
125 126 127 |
# File 'lib/restate/context.rb', line 125 def workflow_send(service, handler, key, arg, delay: nil, idempotency_key: nil, headers: nil, input_serde: NOT_SET) end |