apalis-file-storage

Crates.ioapalis-file-storage
lib.rsapalis-file-storage
version0.1.0-rc.2
created_at2025-12-24 11:45:15.269306+00
updated_at2026-01-07 05:47:19.944805+00
descriptionA test-friendly single process file-based storage backend for apalis
homepagehttps://github.com/apalis-dev/apalis
repositoryhttps://github.com/apalis-dev/apalis
max_upload_size
id2003012
size52,556
Njuguna Mureithi (geofmureithi)

documentation

https://docs.rs/apalis-file-storage

README

File based backends

File-based backend for persisting tasks and results. Currently only supports JSON.

Features

  • Sink support: Ability to push new tasks.
  • Codec Support: Serialization support for arguments using JSON.
  • Workflow Support: Flexible enough to support workflows.
  • Ack Support: Allows acknowledgement of task completion.
  • WaitForCompletion: Wait for tasks to complete without blocking.

Usage Example

use apalis_file_storage::JsonStorage;
use apalis_core::worker::builder::WorkerBuilder;
use std::time::Duration;
use apalis_core::worker::context::WorkerContext;
use apalis_core::backend::TaskSink;
use apalis_core::error::BoxDynError;
use apalis_core::worker::ext::event_listener::EventListenerExt;

#[tokio::main]
async fn main() {
    let mut json_store = JsonStorage::new_temp().unwrap();
    json_store.push(42).await.unwrap();


    async fn task(task: u32, ctx: WorkerContext) -> Result<(), BoxDynError> {
        tokio::time::sleep(Duration::from_secs(1)).await;
        ctx.stop().unwrap();
        Ok(())
    }

    let worker = WorkerBuilder::new("rango-tango")
        .backend(json_store)
        .on_event(|ctx, ev| {
            println!("On Event = {:?}", ev);
        })
        .build(task);
    worker.run().await.unwrap();
}

Implementation Notes

  • Tasks are stored in a file, each line representing a serialized task entry.
  • All operations are thread-safe using RwLock.
  • Data is atomically persisted to disk to avoid corruption.
  • Supports temporary storage for testing and ephemeral use cases.
Commit count: 628

cargo fmt