Ask questions[BUG] Setting runOnInit executes onTick with false start

OnTick is running when runOnTick is true and start is false.

Any solution to this problem?


Answer questions intcreator

I do think it's kind of confusing but runOnInit runs the function when the cron job is initalized which is a different moment from when it is started.

import { CronJob } from "cron";

const job = new CronJob({
    cronTime: "* * * * *",
    onTick: () => console.log("Tick"),
    runOnInit: true,
    startNow: false,
// should see "Tick" once in the console even though job has not started

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


Related questions

No questions were found.
Brandon der Blätter intcreator Interlucid Pleasant Grove, UT part time rockstar developer, part time actual rockstar. if my code helped you, check out my music 🙂👇
Github User Rank List