-
Notifications
You must be signed in to change notification settings - Fork 621
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
[BUG] Setting runOnInit executes onTick with false start #574
Comments
Same here, some workaround? 👀 |
can you add a test case that illustrates this issue? |
import { CronJob } from "cron";
const job = new CronJob({
cronTime: "* * * * *",
onTick: () => console.log("Tick"),
runOnInit: true,
startNow: false, // startNow is false by default anyway
}); It fires the tick every minute even if you never do |
I believe this is expected behavior for this option. there is an existing test that shows that the function is called as soon as the job is defined but before it is started. perhaps this could be clarified in the documentation |
I think it makes no sense since you can achieve it with the config but you cant achieve the other behavior :/ You can config |
actually when I run the code example you provided it only runs once for me. what are you expecting |
For "on init" we understand "on start" but if the cron didn't start yet I think the cron must not run. How else can I achieve that behavior? Btw: I really appreciate your work on it |
I do think it's kind of confusing but
once you start the job you should see "Tick" in the console every second. if you are not starting the job but you are seeing "Tick" appear every second instead of just once, then that would be a bug. but you should be able to replicate that with a test case similar to the other test cases we have in the repo |
Oh ok, you are right! I understood. Maybe its a bit confusing How can I run the job on start? |
I'm not sure there's a built in way to do that, but it should be easy enough to extract your job to a function and then call that function when you call |
@frbuceta is this the issue you were experiencing or was there a bug where I'm going to close this for now since it's an old issue that I can't duplicate and I think it's getting a bit off topic. I'm still open to adding a |
OnTick is running when runOnTick is true and start is false.
Any solution to this problem?
The text was updated successfully, but these errors were encountered: