34 releases

0.6.0-rc.8 Oct 11, 2024
0.6.0-rc.5 Jul 25, 2024
0.5.5 Sep 5, 2024
0.5.1 Mar 13, 2024
0.3.4 Sep 20, 2022

#916 in Asynchronous

Download history 3145/week @ 2024-07-12 2899/week @ 2024-07-19 2924/week @ 2024-07-26 3094/week @ 2024-08-02 3088/week @ 2024-08-09 3161/week @ 2024-08-16 2922/week @ 2024-08-23 3044/week @ 2024-08-30 2060/week @ 2024-09-06 2000/week @ 2024-09-13 1690/week @ 2024-09-20 1231/week @ 2024-09-27 1636/week @ 2024-10-04 897/week @ 2024-10-11 1552/week @ 2024-10-18 1446/week @ 2024-10-25

5,676 downloads per month
Used in 5 crates (via apalis)

MIT license

160KB
3.5K SLoC

apalis-cron

A simple yet extensible library for cron-like job scheduling for rust. Since apalis-cron is build on top of apalis which supports tower middleware, you should be able to easily add middleware such as tracing, retries, load shed, concurrency etc.

Example

use apalis::layers::retry::RetryLayer;
use apalis::layers::retry::RetryPolicy;
use tower::ServiceBuilder;
use apalis_cron::Schedule;
use std::str::FromStr;
use apalis::prelude::*;
use apalis_cron::CronStream;
use chrono::{DateTime, Utc};

#[derive(Clone)]
struct FakeService;
impl FakeService {
    fn execute(&self, item: Reminder){}
}

#[derive(Default, Debug, Clone)]
struct Reminder(DateTime<Utc>);
impl From<DateTime<Utc>> for Reminder {
   fn from(t: DateTime<Utc>) -> Self {
       Reminder(t)
   }
}
async fn send_reminder(job: Reminder, svc: Data<FakeService>) {
    svc.execute(job);
}

#[tokio::main]
async fn main() {
    let schedule = Schedule::from_str("@daily").unwrap();
    let worker = WorkerBuilder::new("morning-cereal")
        .layer(RetryLayer::new(RetryPolicy::retries(5)))
        .data(FakeService)
        .stream(CronStream::new(schedule).into_stream())
        .build_fn(send_reminder);
    Monitor::<TokioExecutor>::new()
        .register(worker)
        .run()
        .await
        .unwrap();
}

Dependencies

~4–14MB
~185K SLoC