mvniekerk / tokio-cron-scheduler

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

Document duration argument for `new_one_shot` methods #70

Closed JosiahParry closed 3 months ago

JosiahParry commented 3 months ago

The Job struct has methods such as new_one_shot() and new_one_shot_async() which require a duration as their first argument.

It is unclear what this argument does as it is not documented nor do the other methods document it.

Does it delay the start of the job?

For other methods such as new_repeated() the duration is inferrable—i.e. it is repeated after the duration, but it is not clear for new_one_shot().

I'd be happy to make a PR updating the documentation if you can clarify it here.

Thanks!

mvniekerk commented 3 months ago

Thank you for the bug report, let me get back to you.

mvniekerk commented 3 months ago

Ok, I've changed the docs. Hopefully it makes it more obvious?

    /// Create a new async one shot job.
    ///
    /// This will schedule a job that is only run once after the duration has passed.
    ///
    /// ```rust,ignore
    /// let mut sched = JobScheduler::new();
    /// 
    ///  let job = Job::new_one_shot_async(Duration::from_secs(16), |_uuid, _l| {
    ///             Box::pin(async move {
    ///                 info!("I'm only run once async");
    ///             })
    ///         })
    ///         .unwrap();
    /// sched.add(job)
    /// tokio::spawn(sched.start());
    /// ```
    /// Above will run the code after 18 seconds, only once
JosiahParry commented 3 months ago

Yes thank you for the clarification!