aj 
aj is a one-stop solution for your background jobs (includes schedule, cron) based on actix engine (actor model).
This project is under development.
Docs
use actix_rt::time::sleep;
use std::time::Duration;
use actix_rt::System;
use aj::async_trait::async_trait;
use aj::mem::InMemory;
use aj::serde::{Deserialize, Serialize};
use aj::{get_now_as_secs, start_engine, AJ};
use aj::{Executable, JobBuilder};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PrintJob {
pub number: i32,
}
#[async_trait]
impl Executable for PrintJob {
type Value = ();
type Error = ();
async fn execute(&self) -> Result<Self::Value, Self::Error> {
println!(
"Hello in background {} at {}",
self.number,
get_now_as_secs()
);
Ok(())
}
}
fn run_job_instantly() {
let job = JobBuilder::new(PrintJob { number: 1 }).build();
AJ::add_job(job);
}
fn main() {
start_engine();
let backend = InMemory::default();
AJ::register::<PrintJob>("print_job", backend);
println!("Now is {}", get_now_as_secs());
run_job_instantly();
std::thread::spawn(|| {
System::new().block_on(async {
sleep(Duration::from_secs(1)).await;
})
})
.join()
.expect("Cannot spawn thread");
}
LICENSE