APScheduler to do jop every day withon 11:15am to 2:15 pm on 15 min delay

Question:

I need to do a job with 15 mins interval within 11:15 am to 2:15 pm IST every day,
I tried using the below code but still i cannot able to get it.
Any answers would be really appreciated.

from apscheduler.schedulers.background import BackgroundScheduler,BlockingScheduler

from datetime import datetime

def my_job():
   print(f"custom job called at {datetime.now()}")
scheduler = BlockingScheduler()
scheduler.add_job(my_job, 'cron', minute='1', hour='12-14')
scheduler.start()
Asked By: SANJAY. R

||

Answers:

The easiest way I see to achieve those times would be to create multiple triggers with the OrTrigger. I also used different cron operators, to make it run every 15 minutes.

from apscheduler.triggers.combining import OrTrigger
from apscheduler.triggers.cron import CronTrigger

trigger = OrTrigger([CronTrigger(hour='11', minute='15-59/15'),
                     CronTrigger(hour='12-13', minute='0-59/15'),
                     CronTrigger(hour='14', minute='0-15/15')])
scheduler.add_job(my_job, trigger)
Answered By: Ethansocal
from apscheduler.triggers.combining import OrTrigger
from apscheduler.triggers.cron import CronTrigger

trigger = OrTrigger([CronTrigger(hour='11', minute='15-59/15'),
                     CronTrigger(hour='12-13', minute='0-59/15'),
                     CronTrigger(hour='14', minute='0-15/15')])
scheduler.add_job(my_job, trigger,timezone='Asia/Kolkata')
scheduler.start()
Answered By: Sanjay Sanjay
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.