mvniekerk / tokio-cron-scheduler

Schedule tasks on Tokio using cron-like annotation
Apache License 2.0
529 stars 59 forks source link

How to use reqwest or blocking inside #63

Closed baerwang closed 7 months ago

baerwang commented 7 months ago
pub async fn execute() -> Result<String, JobSchedulerError> {
    let sched = JobScheduler::new().await?;
    let task = Job::new_repeated(Duration::from_secs(20), move |_uuid, _l| {
        let resp = reqwest::Client::new()
            .get("https://example.com")
            .timeout(Duration::from_secs(3))
            .send()
            .await?
            .text()
            .await?;

        println!("{:?}", resp)
    })?;
    let uuid = sched.add(task).await?;
    sched.start().await?;
    Ok(uuid.to_string())
}