Skip to main content

Crate apalis_file_storage

Crate apalis_file_storage 

Source
Expand description

§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, worker: WorkerContext) -> Result<(), BoxDynError> {
        tokio::time::sleep(Duration::from_secs(1)).await;
        worker.stop().unwrap();
        Ok(())
    }

    let worker = WorkerBuilder::new("rango-tango")
        .backend(json_store)
        .on_event(|worker, 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.

Structs§

CsvAdapter
A CSV adapter for serializing and deserializing tasks.
FileStorage
A backend that persists to a file using json encoding
JsonAdapter
A JSON adapter for serializing and deserializing tasks.
SharedJsonStore
Sharable JSON based backend.

Enums§

SyncPolicy
Handles the sync policy for when to flush pending changes to disk.

Traits§

Adapter
Pluggable serialization strategy for FileStorage.

Type Aliases§

CsvStorage
A FileStorage using CsvAdapter for line encoding.
JsonStorage
A FileStorage using JsonAdapter for line encoding.