Running APScheduler Job Every nth Day of Month

2019-08-09 16:00发布

问题:

I'm looking for an APScheduler trigger that will execute a job every nth day of a month. For example, I want to run a job on the first Tuesday of every month. Or on the first and third Monday of every month.

Does anyone have a trigger that accomplishes this? You can almost do it with the cron scheduler and having your function double-check that it's running at the right time: Cron job to run every first or last chosen day of week of every month

回答1:

Using the documentation of the cron trigger:

scheduler.add_job(func, 'cron', day='1st tue')
scheduler.add_job(func, 'cron', day='1st mon,3rd mon')
scheduler.add_job(func, 'cron', day='1st fri,last fri')