Skip to main content

ActorContext

Struct ActorContext 

Source
pub struct ActorContext(/* private fields */);
Expand description

Shared actor runtime context.

This public surface is the foreign-runtime contract for rivetkit-core. Native Rust, NAPI-backed TypeScript, and future V8 runtimes should be able to drive actor behavior through ActorFactory plus the methods exposed here and on the returned runtime objects like SqliteDb, schedule APIs, queue APIs, ConnHandle, and WebSocket.

Implementations§

Source§

impl ActorContext

Source

pub async fn kv_batch_get(&self, keys: &[&[u8]]) -> Result<Vec<Option<Vec<u8>>>>

👎Deprecated:

Actor KV is deprecated. Use embedded SQLite (sql()) or actor state instead.

Source

pub async fn kv_batch_put(&self, entries: &[(&[u8], &[u8])]) -> Result<()>

👎Deprecated:

Actor KV is deprecated. Use embedded SQLite (sql()) or actor state instead.

Source

pub async fn kv_batch_delete(&self, keys: &[&[u8]]) -> Result<()>

👎Deprecated:

Actor KV is deprecated. Use embedded SQLite (sql()) or actor state instead.

Source

pub async fn kv_delete_range(&self, start: &[u8], end: &[u8]) -> Result<()>

👎Deprecated:

Actor KV is deprecated. Use embedded SQLite (sql()) or actor state instead.

Source

pub async fn kv_list_prefix( &self, prefix: &[u8], opts: ListOpts, ) -> Result<Vec<(Vec<u8>, Vec<u8>)>>

👎Deprecated:

Actor KV is deprecated. Use embedded SQLite (sql()) or actor state instead.

Source

pub async fn kv_list_range( &self, start: &[u8], end: &[u8], opts: ListOpts, ) -> Result<Vec<(Vec<u8>, Vec<u8>)>>

👎Deprecated:

Actor KV is deprecated. Use embedded SQLite (sql()) or actor state instead.

Source

pub fn kv(&self) -> &ActorKv

👎Deprecated:

Actor KV is deprecated. Use embedded SQLite (sql()) or actor state instead.

Source

pub fn sql(&self) -> &SqliteDb

Source

pub async fn db_exec(&self, sql: &str) -> Result<Vec<u8>>

Source

pub async fn db_query( &self, sql: &str, params: Option<&[u8]>, ) -> Result<Vec<u8>>

Source

pub async fn db_execute( &self, sql: &str, params: Option<&[u8]>, ) -> Result<Vec<u8>>

Source

pub async fn db_run(&self, sql: &str, params: Option<&[u8]>) -> Result<()>

Source

pub fn set_alarm(&self, timestamp_ms: Option<i64>) -> Result<()>

Source

pub async fn init_alarms(&self)

Resync persisted alarms with the runtime’s alarm transport.

Foreign-runtime adapters should call this during startup after loading any persisted schedule state and before accepting user callbacks that rely on future alarms being armed.

Source

pub fn queue(&self) -> &Self

Source

pub fn sleep(&self) -> Result<()>

Source

pub fn destroy(&self) -> Result<()>

Source

pub fn stop_with_error(&self, message: impl Into<String>) -> Result<()>

Request a stop with an error attached. Behaves like Self::destroy locally (destroy grace hooks run for this generation), but the envoy reports the stop to the engine with StopCode::Error and the message, so the engine records the crash and applies its crash handling instead of unconditionally destroying the actor.

Source

pub fn mark_destroy_requested(&self)

Source

pub fn set_prevent_sleep(&self, _enabled: bool)

👎Deprecated:

no-op: use keep_awake or wait_until instead

Deprecated no-op. Use keep_awake to hold the actor awake for the duration of a future, or wait_until to keep work alive across the sleep grace period. Retained only for NAPI bridge compatibility.

Source

pub fn prevent_sleep(&self) -> bool

👎Deprecated:

no-op: always returns false

Source

pub fn wait_until(&self, future: impl Future<Output = ()> + Send + 'static)

Source

pub fn register_task(&self, future: impl Future<Output = ()> + Send + 'static)

Source

pub async fn keep_awake<F>(&self, future: F) -> F::Output
where F: Future,

Source

pub fn keep_awake_region(&self) -> KeepAwakeRegion

Source

pub async fn internal_keep_awake<F>(&self, future: F) -> F::Output
where F: Future,

Source

pub fn keep_awake_count(&self) -> usize

Source

pub fn internal_keep_awake_count(&self) -> usize

Source

pub async fn track_work<F>(&self, kind: ActorWorkKind, future: F) -> F::Output
where F: Future,

Source

pub fn spawn_work<F>(&self, kind: ActorWorkKind, future: F)
where F: Future<Output = ()> + Send + 'static,

Source

pub fn begin_work_region(&self, kind: ActorWorkKind) -> ActorWorkRegion

Source

pub fn actor_id(&self) -> &str

Source

pub fn name(&self) -> &str

Source

pub fn key(&self) -> &ActorKey

Source

pub fn region(&self) -> &str

Source

pub fn has_state(&self) -> bool

Source

pub fn broadcast(&self, name: &str, args: &[u8])

Source

pub fn conns(&self) -> ConnHandles<'_>

Returns a lock-backed iterator over live connections.

Do not hold the returned iterator across .await. It keeps a read lock on the connection map until dropped, which blocks connection writers.

Source

pub fn client_endpoint(&self) -> Option<&str>

Source

pub fn client_token(&self) -> Option<&str>

Source

pub fn client_namespace(&self) -> Option<&str>

Source

pub fn client_pool_name(&self) -> Option<&str>

Source

pub fn ack_hibernatable_websocket_message( &self, gateway_id: &[u8], request_id: &[u8], server_message_index: u16, ) -> Result<()>

Source

pub async fn drain_overdue_scheduled_events(&self) -> Result<()>

Dispatches any scheduled actions whose deadline has already passed.

Foreign-runtime adapters should call this after startup callbacks complete so overdue scheduled work enters the normal actor event loop.

Source

pub async fn connect_conn_with_request<F>( &self, params: Vec<u8>, request: Option<Request>, create_state: F, ) -> Result<ConnHandle>
where F: Future<Output = Result<Vec<u8>>> + Send,

Source

pub async fn disconnect_conn(&self, id: ConnId) -> Result<()>

Source

pub async fn disconnect_conns<F>(&self, predicate: F) -> Result<()>
where F: FnMut(&ConnHandle) -> bool,

Source

pub fn queue_hibernation_removal(&self, conn_id: impl Into<String>)

Source

pub fn has_pending_hibernation_changes(&self) -> bool

Source

pub fn take_pending_hibernation_changes(&self) -> Vec<ConnId>

Source

pub fn dirty_hibernatable_conns(&self) -> Vec<ConnHandle>

Source

pub fn inspector_snapshot(&self) -> InspectorSnapshot

Source

pub fn is_destroy_requested(&self) -> bool

Source

pub async fn wait_for_destroy_completion_public(&self)

Source

pub async fn with_disconnect_callback<F, Fut, T>(&self, run: F) -> T
where F: FnOnce() -> Fut, Fut: Future<Output = T>,

Source

pub fn websocket_callback_region(&self) -> WebSocketCallbackRegion

Source§

impl ActorContext

Source

pub async fn send(&self, name: &str, body: &[u8]) -> Result<QueueMessage>

Source

pub async fn enqueue_and_wait( &self, name: &str, body: &[u8], opts: EnqueueAndWaitOpts, ) -> Result<Option<Vec<u8>>>

Source

pub async fn next(&self, opts: QueueNextOpts) -> Result<Option<QueueMessage>>

Source

pub async fn next_batch( &self, opts: QueueNextBatchOpts, ) -> Result<Vec<QueueMessage>>

Source

pub async fn wait_for_names( &self, names: Vec<String>, opts: QueueWaitOpts, ) -> Result<QueueMessage>

Source

pub async fn wait_for_names_available( &self, names: Vec<String>, opts: QueueWaitOpts, ) -> Result<()>

Source

pub fn try_next(&self, opts: QueueTryNextOpts) -> Result<Option<QueueMessage>>

Source

pub fn try_next_batch( &self, opts: QueueTryNextBatchOpts, ) -> Result<Vec<QueueMessage>>

Source

pub async fn inspect_messages(&self) -> Result<Vec<QueueMessage>>

Source

pub fn max_size(&self) -> u32

Source

pub async fn reset(&self) -> Result<()>

Removes all messages from the queue and resets the size counter.

Source§

impl ActorContext

Source

pub async fn after( &self, duration: Duration, action_name: &str, args: &[u8], ) -> Result<String>

Source

pub async fn at( &self, timestamp_ms: i64, action_name: &str, args: &[u8], ) -> Result<String>

Source

pub async fn cancel_schedule(&self, event_id: &str) -> Result<bool>

Source

pub async fn get_scheduled_event( &self, event_id: &str, ) -> Result<Option<ScheduledEventInfo>>

Source

pub async fn list_scheduled_events(&self) -> Result<Vec<ScheduledEventInfo>>

Source

pub async fn cron_set( &self, name: &str, expression: &str, timezone: Option<&str>, action_name: &str, args: &[u8], max_history: Option<i64>, ) -> Result<()>

Source

pub async fn cron_every( &self, name: &str, interval_ms: i64, action_name: &str, args: &[u8], max_history: Option<i64>, ) -> Result<()>

Source

pub async fn cron_delete(&self, name: &str) -> Result<bool>

Source

pub async fn cron_get(&self, name: &str) -> Result<Option<CronJobInfo>>

Source

pub async fn cron_list(&self) -> Result<Vec<CronJobInfo>>

Source

pub async fn cron_history( &self, name: &str, limit: Option<i64>, ) -> Result<Vec<CronFire>>

Source§

impl ActorContext

Source§

impl ActorContext

Source

pub fn state(&self) -> Vec<u8>

Source

pub fn set_state_initial(&self, state: Vec<u8>)

Foreign-runtime bootstrap hook for installing the actor state snapshot before the actor starts handling lifecycle/dispatch work.

Source

pub fn request_save(&self, opts: RequestSaveOpts)

Fire-and-forget save request helper.

If the lifecycle event inbox is unavailable, this only logs a warning and returns. That warn! is the sole failure signal for this path; callers do not receive a Result. Call Self::request_save_and_wait when the caller must observe save-request delivery failures.

Source

pub async fn request_save_and_wait(&self, opts: RequestSaveOpts) -> Result<()>

Source

pub async fn save_state(&self, deltas: Vec<StateDelta>) -> Result<()>

Source

pub async fn save_state_and_workflow_batch( &self, workflow_writes: Vec<WorkflowKvWrite>, ) -> Result<()>

Requests one logical workflow-engine flush. The actor lifecycle owns serializing actor state and committing both sides in one SQLite transaction.

Source

pub fn begin_on_state_change(&self) -> OnStateChangeGuard

Source

pub fn on_state_change_started(&self)

Source

pub fn on_state_change_finished(&self)

Source

pub fn persisted(&self) -> PersistedActor

Source

pub fn load_persisted(&self, persisted: PersistedActor)

Source

pub fn scheduled_events(&self) -> Vec<PersistedScheduleEvent>

Source

pub fn set_scheduled_events( &self, scheduled_events: Vec<PersistedScheduleEvent>, )

Source

pub fn set_input(&self, input: Option<Vec<u8>>)

Source

pub fn input(&self) -> Option<Vec<u8>>

Source

pub fn set_has_initialized(&self, has_initialized: bool)

Source

pub fn has_initialized(&self) -> bool

Source

pub fn flush_on_shutdown(&self)

Source

pub fn on_request_save(&self, hook: Box<dyn Fn(RequestSaveOpts) + Send + Sync>)

Trait Implementations§

Source§

impl Clone for ActorContext

Source§

fn clone(&self) -> ActorContext

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ActorContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> RuntimeFutureOutput for T
where T: Send + 'static,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more