Skip to content

How to configure a cron job to run every other week on a certain day #176

Answered by Hexagon
mohammedmulazada asked this question in Q&A
Discussion options

You must be logged in to vote

It isn't possible by using a cron expression alone, as the aspect of weeks isn't included in the pattern. So you'll have to make use of some library features 😄

Continuing on your solution where the job is executed between dates 7-14.22-28 every months, you'll have to disable legacyMode.

By default cron uses OR to combine day of month with day of week, making the expression execute every mondag AND day 7-14 and 22-28.

legacyMode: false changes this behavior to AND.

This should work better:

const job = Cron("40 9 7-14,22-28 * 1", { legacyMode: false}, (job) => {});
console.log(job.nextRuns(10));

Another way would be to use a minimum interval between executions, which is larger than one week…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mohammedmulazada
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants