Expand description
Shared background task primitives for Aster services.
This crate owns product-neutral task mechanics: step state transitions, typed payload/result serialization, retry classification, erased task-spec adapters, registry generation, runtime worker loops, lease guards, heartbeat loops, lane claiming, dispatch aggregation, drain loops, and task artifact temporary-directory helpers. It deliberately does not own database entities, SeaORM repositories, product task kind enums, runtime configuration, metrics labels, or concrete task implementations. Product crates keep those boundaries and register their specs and storage adapters explicitly.
Macros§
- runtime_
task_ registry - Generates product-local runtime task metadata lookup functions.
- task_
registry - Generates a product-local static task registry.
Structs§
- Background
Task Dispatch Backoff - Adaptive idle backoff for background task dispatch workers.
- Background
Task Dispatch Iteration - Activity summary returned by one dispatch iteration.
- Background
Task Runtime Component - Runtime component that owns spawned background task handles.
- Background
Task Runtime Component From Shutdown - Runtime builder component that spawns background tasks from the shared shutdown token.
- Background
Task Runtime Definitions Component - Runtime component that owns spawned task handles and registers task definitions.
- Background
Task Runtime Definitions Component From Shutdown - Runtime builder component that spawns background tasks and registers task definitions.
- Background
Tasks - Shutdown-aware collection of spawned background workers.
- Claimed
Task - Successfully claimed task metadata.
- Claimed
Task Execution Config - Configuration for the shared claimed-task execution lifecycle.
- Dispatch
Stats - Aggregate counters returned by a background task dispatch pass.
- Leased
Scheduled Runtime Config - Configuration for a leased group of scheduled runtime tasks.
- Periodic
Task - Configuration for one periodic runtime task worker.
- Recorded
Task Hooks - Product callbacks used by panic-protected recorded task iterations.
- Runtime
Task Definition - Product-owned runtime task metadata registered with Forge helpers.
- Scheduled
Periodic Task - Configuration for one scheduled periodic runtime task worker.
- Scheduled
Runtime Task Group - Lease-scoped task group used by product registration closures.
- Scheduled
Task Catalog Entry - One scheduled runtime task entry registered by a product runtime.
- Scheduled
Task Claim - Claimed scheduled task firing.
- Scheduled
Task Claim Renewal - Renewal update for a claim whose task body is still running.
- Scheduled
Task Claim Request - Request to atomically claim one due scheduled task firing.
- Scheduled
Task Completion - Completion update for a claimed scheduled task.
- Task
Claim Candidate - Candidate task selected for compare-and-swap claiming.
- Task
Dedupe Key - Validated task dedupe key.
- Task
Dispatch Outcome - Counters returned by one claimed task execution.
- Task
Execution Context - Task execution context passed to product task implementations.
- Task
Lane Config - Product-owned dispatch lane configuration.
- Task
Lease - Persisted processing lease assigned when a task is claimed.
- Task
Lease Guard - Shared in-memory lease guard observed by task code and heartbeat code.
- Task
Permanent Failure - Failure update passed to product storage after a task exhausts automatic retry.
- Task
Retry Update - Retry update passed to product storage after an automatically retryable failure.
- Task
Spec Adapter - Zero-sized adapter from typed task specs to object-safe task specs.
- Task
Step Info - Serialized task step shown in task APIs.
- Task
Step Spec - Static step definition used to create initial task steps.
Enums§
- Background
Task Dispatch Trigger - Reason a dispatch loop is about to run an iteration.
- Runtime
Task Name - Runtime task name stored in product payloads.
- Task
Core Error - Error returned by shared task helpers before product-level mapping.
- Task
Retry Class - Retry behavior selected after a task failure.
- Task
Step Status - Runtime status for a task step.
Constants§
- BACKGROUND_
TASKS_ COMPONENT - Stable component name used for background task workers.
- BACKGROUND_
TASKS_ SHUTDOWN_ PHASE - Stable shutdown phase name for background task workers.
- BACKGROUND_
TASK_ DISPATCH_ ERROR_ BACKOFF_ CAP - Minimum backoff used after a dispatch iteration returns an error.
- BACKGROUND_
TASK_ SHUTDOWN_ GRACE - Default grace period used when shutting down background workers.
- TASK_
DEDUPE_ KEY_ MAX_ LEN - Maximum length for persisted task dedupe keys.
Traits§
- Background
Task Spec - Product-owned typed task specification.
- Claimable
Task Record - Minimal task row view required by generic claim logic.
- Claimed
Task Execution Store - Product hooks required by the shared claimed-task execution lifecycle.
- Erased
Background Task Spec - Object-safe task spec used by registries and dispatchers.
- Executable
Task Record - Minimal read-only view required to execute a claimed task.
- Registered
Runtime Task Kind - Lookup contract implemented by product-owned runtime task enums.
- Scheduled
Task Store - Persistence contract used by scheduled task runners.
- Task
Claim Store - Product storage adapter required by generic lane claiming.
- Task
Heartbeat Store - Product storage adapter used by the generic heartbeat loop.
- Task
Record - Minimal read-only view over a persisted task row.
Functions§
- available_
lane_ capacity - Returns remaining lane capacity after subtracting currently active tasks.
- background_
task_ component - Creates the background task runtime component used by product entrypoints.
- background_
task_ component_ from_ shutdown - Creates a runtime component that spawns background tasks from the shared shutdown token.
- background_
task_ component_ with_ definitions - Creates the background task runtime component with product task definitions.
- background_
task_ component_ with_ definitions_ from_ shutdown - Creates a task-definition component that spawns workers from the shared shutdown token.
- boxed_
task_ future - Converts an operation into a boxed future.
- claim_
due_ for_ lane - Claims due tasks for a single lane using a product storage adapter.
- claim_
limit_ to_ u64 - Converts a lane limit into the
u64shape used by database query limits. - cleanup_
runtime_ temp_ root - Cleans the short-lived runtime temporary directory under
temp_root. - cleanup_
task_ temp_ dir_ for_ lease_ in_ root - Cleans the token-scoped temporary directory for one claimed task lease.
- cleanup_
task_ temp_ dir_ for_ task_ in_ root - Cleans every temporary artifact directory for one persisted task id.
- cleanup_
temp_ dir - Cleans a temporary directory tree, logging failures instead of returning them.
- decode_
payload_ as - Decodes a task payload as the typed payload for
S. - decode_
result_ as - Decodes a task result as the typed result for
S. - default_
task_ retry_ delay_ secs - Default retry delay used by Aster task dispatchers.
- dispatch_
lanes - Runs lane dispatchers concurrently and aggregates lane statistics.
- drain_
dispatcher - Drains a dispatcher until it has no claimed work and no active processing tasks.
- effective_
dispatch_ base_ interval - Returns the effective dispatch base interval, enforcing a one-second minimum.
- effective_
dispatch_ max_ interval - Returns the effective maximum dispatch interval.
- effective_
jitter_ cap - Returns the effective jitter cap for one periodic interval.
- evaluate_
heartbeat_ result - Evaluates one persisted heartbeat result and updates the in-memory lease guard.
- initial_
task_ steps_ from_ specs - Creates initial task step state from static specs.
- mark_
active_ step_ failed - Marks the active step failed, or the last pending step when no step is active.
- next_
scheduled_ run_ at - Computes the next run timestamp after a completed scheduled task firing.
- periodic_
sleep_ duration - Returns a periodic delay with bounded positive jitter.
- prepare_
task_ temp_ dir_ in_ root - Prepares the token-scoped temporary directory for one claimed task lease.
- process_
claimed_ task - Runs one claimed task through heartbeat, processing, retry, and failure handling.
- run_
claimed_ task_ batch - Runs an already claimed task batch and aggregates task execution outcomes.
- run_
claimed_ task_ batch_ with_ store - Runs a claimed task batch using the shared lifecycle and aggregates counters.
- run_
dispatch_ worker - Runs a wakeable dispatch loop with adaptive idle backoff.
- run_
leased_ background_ tasks - Runs a singleton background task group behind a Forge runtime lease.
- run_
periodic_ task - Runs a periodic task until shutdown.
- run_
recorded_ task_ iteration - Runs one panic-protected task iteration and records its outcome.
- run_
scheduled_ claim_ renewal_ loop - Renews one owned scheduled task claim until stopped or the claim is lost.
- run_
scheduled_ periodic_ task - Runs a scheduled periodic task until shutdown.
- run_
task_ heartbeat_ loop - Runs heartbeat updates until stopped, the persisted lease is lost, or renewal times out.
- run_
with_ concurrency_ limit - Runs item handlers with a bounded number of in-flight futures.
- scheduled_
claim_ renew_ interval - Derives the claim renewal tick from the claim TTL.
- scheduled_
task_ dedupe_ key - Builds a stable dedupe key for one scheduled task firing.
- serialize_
payload - Serializes a typed task payload.
- serialize_
result - Serializes a typed task result.
- set_
task_ step_ active - Marks a task step active.
- set_
task_ step_ skipped - Marks a task step skipped.
- set_
task_ step_ succeeded - Marks a task step succeeded.
- spawn_
task_ heartbeat_ with_ interval - Spawns a heartbeat worker with the provided interval.
- stop_
task_ heartbeat - Stops and awaits a heartbeat worker.
- task_
lease_ expires_ at - Returns the persisted lease expiry timestamp for a claim or heartbeat update.
- task_
lease_ renewal_ timeout - Returns the in-memory renewal timeout used to stop unsafe workers.
Type Aliases§
- Result
- Result type returned by shared task helpers.
- Task
Process Future - Boxed future returned by task processors.