2

I am trying to run a job between monday hour 0 to friday 19 and add second job scheduled in friday 20. It's not working, Not sure when combining multiple trigger for cron & interval works this way.

from apscheduler.triggers.combining import AndTrigger,OrTrigger
from apscheduler.triggers.interval import IntervalTrigger
from apscheduler.triggers.cron import CronTrigger
from apscheduler.schedulers.blocking import BlockingScheduler
scheduler = BlockingScheduler()

def job():
        print('job started in mon 0, will be executed each minute until fri 19')

def job_report():
        print('end job & report mail to team in fri 20')


trigger1 = OrTrigger([IntervalTrigger(minutes=1),
                      CronTrigger(day_of_week='mon', hour=0),
                      CronTrigger(day_of_week='fri',hour=19)])

trigger2 = OrTrigger([CronTrigger(day_of_week='fri',hour=20)])

scheduler.add_job(job, trigger1)
scheduler.add_job(job_report, trigger2)

scheduler.start()

Or should I use standard cron from aps? For example-

sched.add_job(job_function, CronTrigger.from_crontab('0 0 1-15 may-aug *'))

Any help will be appreciated.

  • Please check troubleshooting section https://apscheduler.readthedocs.org/en/latest/ – estinamir Mar 22 '20 at 00:22
  • I think there's something wrong with my code, not version of aps scheduler. Specially And or Or trigger. I have used Or with three Cron in single trigger / somewhere it went wrong. – Rajib Kumar Dey Mar 22 '20 at 01:19

1 Answers1

3

trigger1 is executed monday to fri from 0:00 to 19:00 every day (not executed from 19:00 to 23:59)

trigger1 = AndTrigger([IntervalTrigger(minutes=1), CronTrigger(day_of_week='mon-fri', hour=0-19)])
Donald Duck
  • 8,409
  • 22
  • 75
  • 99
  • One thing that is wrong here: hour kwarg should be `hour="0-19"` as it interval, it should be written as string. – XCanG Aug 31 '22 at 08:35