8 releases

new 0.6.7 Oct 26, 2024
0.6.6 Oct 26, 2024

#26 in #background-jobs

Download history 190/week @ 2024-10-06 337/week @ 2024-10-13 428/week @ 2024-10-20

958 downloads per month
Used in 2 crates

MIT/Apache

76KB
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
~312K SLoC