mvniekerk / tokio-cron-scheduler

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

How to use reqwest or blocking inside #63

Closed baerwang closed 2 months ago

baerwang commented 3 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())
}