9 releases

0.7.0 Oct 30, 2024
0.6.7 Oct 26, 2024

#26 in #background-jobs

Download history 367/week @ 2024-10-08 299/week @ 2024-10-15 376/week @ 2024-10-22 152/week @ 2024-10-29 23/week @ 2024-11-05

866 downloads per month
Used in 2 crates

MIT/Apache

86KB
2K SLoC

use std::time::Duration;

use aj::{
    async_trait,
    main,
    BackgroundJob, Executable, JobBuilder, JobContext, AJ,
    export::core:: {
        actix_rt::time::sleep,
        serde::{Deserialize, Serialize},
    }
};

#[derive(BackgroundJob, Serialize, Deserialize, Debug, Clone)]
pub struct AJob;

#[async_trait]
impl Executable for AJob {
    type Output = ();

    async fn execute(&self, _context: &JobContext) -> Self::Output {
        println!("Hello Job");
    }
}

#[main]
async fn main() {
    // Start AJ engine with in memory backend.
    AJ::quick_start();

    // Run a Job in Background
    let message = AJob;
    let _ = message
        .job_builder()
        .build()
        .unwrap()
        .run_background()
        .await;

    // Wait this thread in 1 sec to view result in background job
    sleep(Duration::from_secs(1)).await;
}

More examples

Dependencies

~11–21MB
~297K SLoC