profile
viewpoint

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?

kelektiv/node-cron

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

useful!

Related questions

No questions were found.
source:https://uonfu.com/
answerer
Brandon der Blätter intcreator Interlucid Pleasant Grove, UT https://vibe.to/interlucid/spotify:auto part time rockstar developer, part time actual rockstar. if my code helped you, check out my music 🙂👇
Github User Rank List