node-cron icon indicating copy to clipboard operation
node-cron copied to clipboard

Command running twice

Open xHaruke opened this issue 4 years ago • 1 comments

So this is my code:

const schedule = require('node-cron')

schedule.schedule('*/41 * 6-20 * * *',()=>{
    console.log('Ran a command @ ', new Date().toString())
})

I am trying to run the command between 6:00 to 20:00 everyday on an interval of 41 seconds but it runs twice in a minute

image

How can I fix it?

xHaruke avatar Feb 23 '22 11:02 xHaruke

I am not affiliates with this lib, but can help you out anyways :)

This is actually how cron is supposed to work. */41 will trigger at 0 and 41. Just as 0/5 always trigger at 0,5,10,15 etc.

See https://github.com/Hexagon/croner/issues/52 for an alternative solution while still using standard cron. This specific issue is absolut months, but could with some simplification be converted to seconds.

Hexagon avatar Mar 02 '22 22:03 Hexagon