async_job

Crates.ioasync_job
lib.rsasync_job
version0.1.4
sourcesrc
created_at2023-11-29 23:11:53.833796
updated_at2023-12-27 12:00:22.626966
descriptionSimple async cron job crate for Rust
homepage
repositoryhttps://github.com/spider-rs/async_job
max_upload_size
id1053671
size30,280
Jeff Mendez (j-mendez)

documentation

https://docs.rs/async_job

README

async_job

A simple trait for async cron jobs in Rust.

Getting Started

  1. cargo add async_job

Usage

use async_job::{Job, Runner, Schedule, async_trait};

struct ExampleJob;

#[async_trait]
impl Job for ExampleJob {
    fn schedule(&self) -> Option<Schedule> {
        Some("1/5 * * * * *".parse().unwrap())
    }
    // run any async or sync task here with mutation capabilities
    async fn handle(&mut self) {
        println!("Hello, I am a cron job running at: {}", self.now());
    }
}

If you need to use a single threaded env disable the default feature and set the feature rt,

Feature Flags

  1. rt: Single threaded tokio runtime.
  2. rt-multi-thread: Multi threaded tokio runtime. Enabled by default

Examples

Run the example with cargo run --example example

Commit count: 4

cargo fmt