-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Working around tick
#1
Comments
Hi there! No worries about cron being nightly-only. To be honest... I use nightly almost exclusively in my projects for various reasons. Having said that, certainly wouldn't mind to eventually make it work on stable at some point. Thanks for the great advice! The amount of CPU time the process uses while idling is very small overall. I'd certainly be interested in having a version of what you describe at some point though. I do worry how well behaved sleeping for prolonged periods would be though. A task that triggered once a year for example. It would also not be able to follow things like updating the system time terribly well. (Ex, I my system hits ntp and ends up moving forward an hour for whatever reason... now the sleep is off an hour until it wakes up). One could have a maximum sleep period I suppose. I would happily accept a pull request if someone wanted to implement this. As it is though, it's working great for me in my production environment as is. Otherwise, I may look into doing it when I find some free time. |
The scheduling system I originally implemented in my program did as described, and slept for long periods until it was needed again. It worked fine unless the system went to sleep. Upon waking, the sleep time is completely inaccurate. This can lead to missed and unexpected runs and it isn't intuitive. |
That's gonna be the main cause of failure on time drifts, I think (computer sleeping, NTP client updating system time for DST, user updating timezone or clock, etc.). You could sleep for a configurable
|
Wow, I forgot I even commented on this repository. Turns out a year later (and still learning Rust) I'm writing a job scheduler but as part of another project. I got to a basic working scheduler for I'll have to extract this code separately into a Rust library but in the meantime, here is the project I'm talking about: https://github.com/brokenthorn/mf-sellout-reporter/tree/dev Right now, I'm looking into If anyone has any suggestions, they're welcome to open issues there or tweet me @brokenthorn. |
Hi! I noticed a crate had taken a dependency on
cron
so I came to check it out. I have a suggestion that's a bit involved, so forgive me in advance.Currently the
JobScheduler
relies on thetick
method to detect jobs that need to be run. This is functional but causes the program to claim a small amount of CPU time even when none of its jobs are active.Each
Schedule
provides anupcoming()
iterator. TheDateTime
values produced by this iterator are inherently sorted from soonest to most distant. Knowing this, you can:UpcomingJob
that holds aDateTime
and anRc<Job>
.UpcomingJobIterator
that providesnext()
by getting the nextupcoming()
DateTime
from theSchedule
and anRc<Job>
reference to the Job and combining them into anUpcomingJob
.Ord
forUpcomingJob
so they can be sorted in order ofDateTime
.UpcomingJobIterator
from eachJob
.next()
UpcomingJob
from each iterator and put it in the heap (as ordered byDateTime
)UpcomingJob
is the next one to run across all of yourJob
s.std::thread::sleep(...)
until that fire time.Rc<Job>
reference in theUpcomingJob
you just removed to get the nextUpcomingJob
for thatJob
and put it in the heap.The
itertools
crate offers a function calledkmerge
that should be able to take care of steps 5-11 for you.Using this approach, your program is guaranteed to be asleep until the next fire time, no matter which job's next.
PS: Sorry about
cron
being nightly-only. It's mostly blocked on BTreeSet'srange
method being unstable. There's an issue tracking this.The text was updated successfully, but these errors were encountered: