-
Notifications
You must be signed in to change notification settings - Fork 629
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
Date race and tasks with a date in the past #390
Comments
I'm not sure I understand. You're worried about triggering a cronjob that does async work and takes longer to return/process than the next execution of the job? |
I mean one-time jobs.
Will this job be executed? |
When the cronTime is a string we attempt to parse it as cron syntax. You'd need to pass in either a |
I mean the case my one-time job is meant to start in couple milliseconds after |
Ok, I see.
And even:
While
never executes. |
Ahh right. -1ms puts your execution in the past so it wouldn't work/execute. Was your original question about whether crons with dates in the past would execute? We can't instantiate a timeout on jobs in the past (-ms wont work) so we just don't. You should have seen an exception from the job with a timeout in the past. https://github.com/kelektiv/node-cron/blob/master/lib/cron.js#L216 |
No, 've never seen any exceptions.
|
This fixes the exception for real dates that are in the past. A real date is a hard JS date or moment object with a specific date and time of execution. Added readme section covering gotchas for ms level time ranges in real date execution. Signed-off-by: Nick Campbell <nicholas.j.campbell@gmail.com>
@jevho Take a look at the commit I just added. I got some time to look at the exception and the code was never reaching it (part of some of the frantic reworking a few months ago I think). I fixed that up and added some notes regarding the execution of some of the MS level time values since that's not going to work for most machines ( Let me know if this doesn't resolve your issue and thanks for your patience! |
I've just tested your commit and got the exception as expected. But the issue remains unresolved.
But this 'milliseconds gap' problem, as you stated in readme Gotchas (which I called 'date race', if it sounds correct), remains opened. Here still could exist problematic dates, which would not set My suggestion, if I may, would be to introduce an additional flag for Update. And what's more, as I see now, a new problem actually appeared:
That is, now we have lost a simple solution to a 'date in the past' problem. |
Why we can't have date in the past?! |
@anotheri Can you explain a little more about what you're trying to do with the dates in the past. I'm very reluctant to make exceptions here, but I'd like to hear more and see if there is a different approach to your problem. Thanks. |
@ncb000gt sure, so the approach I am using atm with
so, to make sure that utility scripts (2) are never be executed automatically i've used to set the past date – it initiated task properly and also never run it w/o manual trigger. Lmk if you need more technical details on that implementation, but i assume the idea of my use case is clear now. |
While receiving bunch of tasks from external source, tasks with date in past should be processed as soon as possible, other tasks should be processed on time.
Issue with a date in the past can be handled with ease:
But what if we run into racing conditions? What if
datetime
is milliseconds close in future?The text was updated successfully, but these errors were encountered: