Skip to content

Add supported of distributed job scheduling #40

Answered by geofmureithi
piaoger asked this question in Q&A
Discussion options

You must be logged in to vote

Maybe what you are looking for is a combination of CronWorker and StorageWorker
Here is a quick example:

async fn enqueue_daily(job: DailyJob, ctx: JobContext) {
    let redis = ctx.data_opt::<RedisStorage>().unwrap();
    redis.push(job).await.unwrap();
}

async fn do_distributed_stuff(job: DailyJob, _ctx: JobContext) {
   .......
}

#[tokio::main]
async fn main() {
    let redis = std::env::var("REDIS_URL").expect("Missing env variable REDIS_URL");
    let storage = RedisStorage::new(redis).await?;

    let schedule = Schedule::from_str("@daily").unwrap();
    let service = ServiceBuilder::new()
        .layer(Extension(storage.clone()))
        .service(job_fn(enqueue_daily));

    let

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by geofmureithi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants
Converted from issue

This discussion was converted from issue #39 on January 06, 2023 07:02.