pub struct Executor { /* private fields */ }Expand description
Executor configuration for a durable worker.
Implementations§
Source§impl Executor
impl Executor
pub fn new(db: DatabaseConnection, executor_id: String) -> Self
pub fn db(&self) -> &DatabaseConnection
pub fn executor_id(&self) -> &str
Sourcepub async fn heartbeat(&self) -> Result<(), DurableError>
pub async fn heartbeat(&self) -> Result<(), DurableError>
Write (or upsert) a heartbeat row for this executor.
Sourcepub fn start_heartbeat(&self, config: &HeartbeatConfig) -> JoinHandle<()>
pub fn start_heartbeat(&self, config: &HeartbeatConfig) -> JoinHandle<()>
Spawn a background tokio task that calls heartbeat() every config.heartbeat_interval.
Returns a JoinHandle so the caller can abort it on graceful shutdown.
Sourcepub async fn recover_stale_tasks(
&self,
staleness_threshold: Duration,
) -> Result<Vec<RecoveredTask>, DurableError>
pub async fn recover_stale_tasks( &self, staleness_threshold: Duration, ) -> Result<Vec<RecoveredTask>, DurableError>
Claim stale tasks from dead workers in a single atomic operation.
Uses FOR UPDATE SKIP LOCKED so multiple executors can run this
concurrently without blocking each other — each executor claims a
disjoint set of tasks.
Catches three cases:
- Tasks whose
executor_idhas a stale heartbeat (> staleness_threshold) - Tasks whose
executor_idhas no heartbeat row at all - Orphaned tasks with NULL
executor_idthat have been RUNNING too long
Claimed tasks go directly to RUNNING (no intermediate PENDING state)
with started_at reset and executor_id set to this executor.
Sourcepub async fn recover(&self) -> Result<Vec<RecoveredTask>, DurableError>
pub async fn recover(&self) -> Result<Vec<RecoveredTask>, DurableError>
Claim timed-out tasks in a single atomic operation.
Uses FOR UPDATE SKIP LOCKED for safe concurrent claiming.
A task is considered timed-out if:
status = 'RUNNING'andstarted_at IS NOT NULLtimeout_mshas elapsed, ordeadline_epoch_mshas passed
Tasks without timeout_ms set are never considered timed-out.
Auto Trait Implementations§
impl Freeze for Executor
impl !RefUnwindSafe for Executor
impl Send for Executor
impl Sync for Executor
impl Unpin for Executor
impl UnsafeUnpin for Executor
impl !UnwindSafe for Executor
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