pub struct ClaimedTask { /* private fields */ }Expand description
A claimed execution with an active lease. The worker processes this task
and must call one of complete(), fail(), or cancel() when done.
The lease is automatically renewed in the background at lease_ttl / 3
intervals. Renewal stops when the task is consumed or dropped.
complete, fail, and cancel consume self — this prevents
double-complete bugs at the type level.
Implementations§
Source§impl ClaimedTask
impl ClaimedTask
pub fn execution_id(&self) -> &ExecutionId
pub fn attempt_index(&self) -> AttemptIndex
pub fn attempt_id(&self) -> &AttemptId
pub fn lease_id(&self) -> &LeaseId
pub fn lease_epoch(&self) -> LeaseEpoch
pub fn input_payload(&self) -> &[u8] ⓘ
pub fn execution_kind(&self) -> &str
pub fn lane_id(&self) -> &LaneId
Sourcepub fn is_lease_healthy(&self) -> bool
pub fn is_lease_healthy(&self) -> bool
Check if the lease is likely still valid based on renewal success.
Returns false if 3 or more consecutive renewal attempts have failed.
Workers should check this before committing expensive or irreversible
side effects. A false return means Valkey may have already expired
the lease and another worker could be processing this execution.
Sourcepub fn consecutive_renewal_failures(&self) -> u32
pub fn consecutive_renewal_failures(&self) -> u32
Number of consecutive lease renewal failures since the last success.
Returns 0 when renewals are working normally. Useful for observability and custom health policies beyond the default threshold of 3.
Sourcepub async fn delay_execution(
self,
delay_until: TimestampMs,
) -> Result<(), SdkError>
pub async fn delay_execution( self, delay_until: TimestampMs, ) -> Result<(), SdkError>
Delay the execution until delay_until.
Releases the lease. The execution moves to delayed state.
Consumes self — the task cannot be used after delay.
Sourcepub async fn move_to_waiting_children(self) -> Result<(), SdkError>
pub async fn move_to_waiting_children(self) -> Result<(), SdkError>
Move execution to waiting_children state.
Releases the lease. The execution waits for child dependencies to complete. Consumes self.
Sourcepub async fn complete(
self,
result_payload: Option<Vec<u8>>,
) -> Result<(), SdkError>
pub async fn complete( self, result_payload: Option<Vec<u8>>, ) -> Result<(), SdkError>
Complete the execution successfully.
Calls ff_complete_execution via FCALL, then stops lease renewal.
Renewal continues during the FCALL to prevent lease expiry under
network latency — the Lua fences on lease_id+epoch atomically.
Consumes self — the task cannot be used after completion.
§Connection errors
If the Valkey connection drops during this call, the returned error
does not guarantee the operation failed — the Lua function may
have committed before the response was lost. Callers should treat
connection errors on complete() as “possibly succeeded” and verify
the execution state via get_execution_state() before retrying.
Sourcepub async fn fail(
self,
reason: &str,
error_category: &str,
) -> Result<FailOutcome, SdkError>
pub async fn fail( self, reason: &str, error_category: &str, ) -> Result<FailOutcome, SdkError>
Fail the execution with a reason and error category.
If the execution policy allows retries, the engine schedules a retry
(delayed backoff). Otherwise, the execution becomes terminal failed.
Returns FailOutcome so the caller knows what happened.
§Connection errors
If the Valkey connection drops during this call, the returned error
does not guarantee the operation failed — the Lua function may
have committed before the response was lost. Callers should treat
connection errors on fail() as “possibly succeeded” and verify
the execution state via get_execution_state() before retrying.
Sourcepub async fn cancel(self, reason: &str) -> Result<(), SdkError>
pub async fn cancel(self, reason: &str) -> Result<(), SdkError>
Cancel the execution.
Stops lease renewal, then calls ff_cancel_execution via FCALL.
Consumes self.
§Connection errors
If the Valkey connection drops during this call, the returned error
does not guarantee the operation failed — the Lua function may
have committed before the response was lost. Callers should treat
connection errors on cancel() as “possibly succeeded” and verify
the execution state via get_execution_state() before retrying.
Sourcepub async fn renew_lease(&self) -> Result<(), SdkError>
pub async fn renew_lease(&self) -> Result<(), SdkError>
Manually renew the lease. Also called by the background renewal task.
Sourcepub async fn update_progress(
&self,
pct: u8,
message: &str,
) -> Result<(), SdkError>
pub async fn update_progress( &self, pct: u8, message: &str, ) -> Result<(), SdkError>
Update progress (pct 0-100 and optional message).
Sourcepub async fn report_usage(
&self,
budget_id: &BudgetId,
dimensions: &[(&str, u64)],
dedup_key: Option<&str>,
) -> Result<ReportUsageResult, SdkError>
pub async fn report_usage( &self, budget_id: &BudgetId, dimensions: &[(&str, u64)], dedup_key: Option<&str>, ) -> Result<ReportUsageResult, SdkError>
Report usage against a budget and check limits.
Non-consuming — the worker can report usage multiple times.
dimensions is a slice of (dimension_name, delta) pairs.
dedup_key prevents double-counting on retries (auto-prefixed with budget hash tag).
Sourcepub async fn create_pending_waitpoint(
&self,
waitpoint_key: &str,
expires_in_ms: u64,
) -> Result<(WaitpointId, WaitpointToken), SdkError>
pub async fn create_pending_waitpoint( &self, waitpoint_key: &str, expires_in_ms: u64, ) -> Result<(WaitpointId, WaitpointToken), SdkError>
Create a pending waitpoint for future signal delivery.
Non-consuming — the worker keeps the lease. Signals delivered to the
waitpoint are buffered. When the worker later calls suspend() with
use_pending_waitpoint, buffered signals may immediately satisfy the
resume condition.
Returns both the waitpoint_id AND the HMAC token required by external callers to buffer signals against this pending waitpoint (RFC-004 §Waitpoint Security).
Sourcepub async fn append_frame(
&self,
frame_type: &str,
payload: &[u8],
metadata: Option<&str>,
) -> Result<AppendFrameOutcome, SdkError>
pub async fn append_frame( &self, frame_type: &str, payload: &[u8], metadata: Option<&str>, ) -> Result<AppendFrameOutcome, SdkError>
Append a frame to the current attempt’s output stream.
Non-consuming — the worker can append many frames during execution. The stream is created lazily on the first append.
Sourcepub async fn suspend(
self,
reason_code: &str,
condition_matchers: &[ConditionMatcher],
timeout_ms: Option<u64>,
timeout_behavior: TimeoutBehavior,
) -> Result<SuspendOutcome, SdkError>
pub async fn suspend( self, reason_code: &str, condition_matchers: &[ConditionMatcher], timeout_ms: Option<u64>, timeout_behavior: TimeoutBehavior, ) -> Result<SuspendOutcome, SdkError>
Suspend the execution, releasing the lease and creating a waitpoint.
The execution transitions to suspended and the worker loses ownership.
An external signal matching the condition will resume the execution.
If condition_matchers is empty, a wildcard matcher is created that
matches ANY signal name. To require an explicit operator resume with
no signal match, pass a sentinel name that no real signal will use.
If buffered signals on a pending waitpoint already satisfy the condition,
returns AlreadySatisfied and the lease is NOT released.
Consumes self — the task cannot be used after suspension.
Sourcepub async fn resume_signals(&self) -> Result<Vec<ResumeSignal>, SdkError>
pub async fn resume_signals(&self) -> Result<Vec<ResumeSignal>, SdkError>
Read the signals that satisfied the waitpoint and triggered this resume.
Non-consuming. Intended to be called immediately after re-claim via
crate::FlowFabricWorker::claim_from_reclaim_grant, before any
subsequent suspend() (which replaces suspension:current).
Returns Ok(vec![]) when this claim is NOT a signal-resume:
- No prior suspension on this execution.
- The prior suspension belonged to an earlier attempt (e.g. the attempt was cancelled/failed and a retry is now claiming).
- The prior suspension was closed by timeout / cancel / operator override rather than by a matched signal.
Reads suspension:current once, filters by attempt_index to
guard against stale prior-attempt records, then fetches the matched
signal_id set from waitpoint_condition’s matcher:N:signal_id
fields and reads each signal’s metadata + payload directly.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ClaimedTask
impl !RefUnwindSafe for ClaimedTask
impl Send for ClaimedTask
impl Sync for ClaimedTask
impl Unpin for ClaimedTask
impl UnsafeUnpin for ClaimedTask
impl !UnwindSafe for ClaimedTask
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
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more