'every other week' expression with CronTrigger

97 views
Skip to first unread message

eric...@gmail.com

unread,
Oct 8, 2020, 10:33:39 AM10/8/20
to APScheduler
Is there a way to schedule things like 'every other Friday at 9am starting on --- ' ?

I gather this is generally a pain to express in cron without some recourse to calculating e.g. whether this is an odd or even week relative to the unix epoch. But wanted to make sure I wasn't missing some way of doing this in APScheduler. It seems like a fairly common need. 

Apologies if this is off-topic or has been asked before and I missed it.

Thanks for this excellent library!

Eric

Alex Grönholm

unread,
Oct 8, 2020, 11:10:06 AM10/8/20
to apsch...@googlegroups.com
eric...@gmail.com kirjoitti 8.10.2020 klo 17.33:
Is there a way to schedule things like 'every other Friday at 9am starting on --- ' ?

I gather this is generally a pain to express in cron without some recourse to calculating e.g. whether this is an odd or even week relative to the unix epoch. But wanted to make sure I wasn't missing some way of doing this in APScheduler. It seems like a fairly common need.

In the 11 years I've worked on APScheduler, I don't recall anybody ever asking for this specific kind of scheduling.

That said, with the cron trigger you'll get pretty close if you list the specific ISO week numbers you want to trigger on (or use "*/2"). The problem with this is that the number of weeks in a year is not constant (2020 has 53 weeks and 2021 has 52). Therefore you may miss a week or have your scheduled task run on successive weeks. Whether this is a problem for you depends on the specific task of course.

With the interval trigger, you could set a starting date on the next Friday at 9 am. However, unless you use a time zone without DST shifts, the job is then going to be run at 8 AM after the switch back to winter time. If not, it shouldn't be a problem.

The only "proper" way to do this in all time zones would be with the new CalendarIntervalTrigger which is part of APScheduler 4. You'd give it a starting date and it would make sure that the task is always run at the same wall clock time in the given time zone, 14 days apart each.


Apologies if this is off-topic or has been asked before and I missed it.

Thanks for this excellent library!

Eric
--
You received this message because you are subscribed to the Google Groups "APScheduler" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apscheduler...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/apscheduler/7727818d-594a-43f9-9854-d96d518f2169n%40googlegroups.com.

eric...@gmail.com

unread,
Oct 8, 2020, 2:15:40 PM10/8/20
to APScheduler
Thanks for the suggestions. I'll look in to both. 
Reply all
Reply to author
Forward
0 new messages