Search code examples
pythonapscheduler

How to use apscheduler to trigger job at specific times?


I am using python apscheduler module to trigger job at irregular intervals for example at 1:30 AM and 11:10 PM on every day, but not able to find a solution to this.

Could you please help me how to do it. I don't want to create two jobs, one for 1:30 AM and 11:10 PM. At least let me know how to do it with crontab so that I will do same with apscheduler. Thanks.

I went through this link https://apscheduler.readthedocs.io/en/v2.1.2/cronschedule.html#available-fields but not getting an idea of how to do it.


Solution

  • APScheduler 3.5.0, due for release shortly, should cover this case:

    from apscheduler.triggers.multi import OrTrigger
    
    trigger = OrTrigger([CronTrigger(hour=1, minute=30), CronTrigger(hour=23, minute=10)]
    scheduler.add_job(yourfunc, trigger)