Skip to main content

Crate taskq

Crate taskq 

Source
Expand description

A small, thread-safe, in-memory task queue.

taskq assigns every submitted task a queue-local TaskId. Submitting a task with an optional TaskKey additionally enables idempotency: the same key cannot be submitted again while its task is still tracked by the queue. Consumers can either poll with SimpleTaskQueue::try_pop_task or wait asynchronously with SimpleTaskQueue::pop_task.

§Example

use taskq::{SimpleTaskQueue, TaskState};

let queue = SimpleTaskQueue::<&str>::new();
let task_id = queue.submit_task("send email")?;

let task = queue.try_pop_task().expect("a task should be queued");
assert_eq!(task.id(), task_id);
assert_eq!(task.payload(), &"send email");

queue.mark_task_success(task.id())?;
assert_eq!(queue.get_task_status(task_id)?.state(), TaskState::Success);

Structs§

SimpleTaskQueue
A bounded, thread-safe, in-memory task queue.
Task
A task received from a queue.
TaskStatus
A snapshot of a task’s lifecycle state and timestamps.

Enums§

TaskError
An error returned by a task queue operation.
TaskState
The lifecycle state of a task.

Traits§

TaskQueue
Common operations implemented by a task queue.

Functions§

is_finished
Returns whether a task state is terminal.

Type Aliases§

TaskId
Identifies a task uniquely within a queue instance.
TaskKey
A caller-provided idempotency key associated with a task.