pub struct ActivityContext { /* private fields */ }Expand description
Handler-facing context for one activity execution.
Implementations§
Source§impl ActivityContext
impl ActivityContext
Sourcepub fn new(
workflow_id: WorkflowId,
run_id: RunId,
activity_id: ActivityId,
attempt: u32,
) -> (Self, ActivityCancellationHandle)
pub fn new( workflow_id: WorkflowId, run_id: RunId, activity_id: ActivityId, attempt: u32, ) -> (Self, ActivityCancellationHandle)
Creates a context and the internal handle that can signal cancellation.
The full dispatch identity is required: an activity execution always
belongs to one (workflow, run, activity, attempt), and a handler reads
the workflow and run back to stamp the transcript events it emits.
Sourcepub fn with_transcript(
workflow_id: WorkflowId,
run_id: RunId,
activity_id: ActivityId,
attempt: u32,
events: UnboundedSender<ActivityEvent>,
) -> (Self, ActivityCancellationHandle)
pub fn with_transcript( workflow_id: WorkflowId, run_id: RunId, activity_id: ActivityId, attempt: u32, events: UnboundedSender<ActivityEvent>, ) -> (Self, ActivityCancellationHandle)
Creates a context whose transcript seam is live, for a host that owns
the receiving end of events.
This is the seam Self::emit_event publishes on: every event a handler
emits carries this context’s (workflow_id, run_id, activity_id, attempt)
identity, which is exactly the key the server’s transcript sequencer
files it under. A host that executes an activity IN PROCESS (the server’s
declared-command path) uses this to hand its own publisher the same
stream a remote worker’s drain would have delivered.
Sourcepub const fn activity_id(&self) -> &ActivityId
pub const fn activity_id(&self) -> &ActivityId
Returns this activity’s identifier.
Sourcepub const fn workflow_id(&self) -> &WorkflowId
pub const fn workflow_id(&self) -> &WorkflowId
Returns the workflow this activity belongs to.
Sourcepub const fn run_id(&self) -> &RunId
pub const fn run_id(&self) -> &RunId
Returns the concrete run this activity was dispatched by.
A handler that emits transcript events through Self::emit_event
stamps this onto every ActivityEvent it builds: the transcript
keyspace is keyed on (workflow, run, activity, attempt), and without
the run two generations of one continue-as-new chain write to the same
stream. Always present — the run is part of the dispatch identity, so
the handler is never handed an absence it cannot resolve.
Sourcepub fn idempotency_key(&self) -> Option<&str>
pub fn idempotency_key(&self) -> Option<&str>
Returns the stable external-effect key delivered with this task.
Live worker tasks always return Some; manually constructed unit-test
contexts return None because they are not attached to a server task.
Sourcepub fn heartbeat(&self, detail: Option<Payload>) -> Result<(), WorkerError>
pub fn heartbeat(&self, detail: Option<Payload>) -> Result<(), WorkerError>
Emits a cooperative heartbeat request for this activity.
This is the PROGRESS channel: handlers call it to attach a progress payload to the activity’s liveness record. LIVENESS itself is owned by the worker runtime, which automatically heartbeats every in-flight activity within the server-assigned heartbeat window — a handler that never calls this still stays live for as long as it genuinely runs. Contexts created without a live heartbeat sender remain no-op contexts for isolated unit tests.
§Errors
Returns WorkerError when an installed heartbeat seam has been closed.
Sourcepub fn emit_event(&self, event: ActivityEvent) -> Result<(), WorkerError>
pub fn emit_event(&self, event: ActivityEvent) -> Result<(), WorkerError>
Emit a neutral agent-observability ActivityEvent onto the transcript
seam (NOI-5b).
Additive and OPTIONAL: on a context created without a live event seam
(every isolated unit test, and every activity that does not run an
instrumented agent) this is a no-op returning Ok(()), so behaviour is
byte-identical to today. When a seam is installed the worker runtime drains
these events and forwards them to the server’s transcript sequencer, which
stamps the commit-allocated store_seq — the producer never assigns it.
Harness-neutral: the payload is a pure aion-core ActivityEvent; the
per-harness mapping lives in the worker-side adapter, never here.
§Errors
Returns WorkerError when an installed event seam has been closed (the
runtime drain end was dropped) — a dropped transcript event is surfaced,
never silently swallowed.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Returns true once cooperative cancellation has been signalled.
Sourcepub async fn cancelled(&self)
pub async fn cancelled(&self)
Resolves when cooperative cancellation is signalled.
§Why the waiter exists BEFORE the flag is read
Notify::notify_waiters reaches the waiters that EXIST at the moment
it is called and stores nothing for a Notified created afterwards —
both halves measured in this module’s
a_notification_is_seen_by_a_waiter_that_existed_before_it_and_lost_on_one_that_did_not.
A waiter that read the flag first and created its Notified second
therefore has a window: the flag reads false, the whole of
ActivityCancellationHandle::cancel runs inside the window, and the
notification is spent before this waiter exists to receive it. It is
then lost FOREVER, because cancellation is signalled exactly once — and
the awaiting side waits on a cancellation that has already happened,
which is a running command that cannot be killed.
So the order is inverted. The Notified future is created and
enable()d — which registers this waiter explicitly, rather than
leaning on the creation-time capture alone — and only then is the flag
read. A cancel that lands before the read is seen by the read; one
that lands after it is seen by the waiter already in place. There is no
third position for it to land in.
The loop is not a spin: Notified completes only on a notification, and
re-entering it creates and registers a new waiter before re-reading, so
every iteration keeps the same ordering.
Trait Implementations§
Source§impl Clone for ActivityContext
impl Clone for ActivityContext
Source§fn clone(&self) -> ActivityContext
fn clone(&self) -> ActivityContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ActivityContext
impl RefUnwindSafe for ActivityContext
impl Send for ActivityContext
impl Sync for ActivityContext
impl Unpin for ActivityContext
impl UnsafeUnpin for ActivityContext
impl UnwindSafe for ActivityContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request