apscheduler.triggers.combining

These triggers combine the behavior of other triggers in different ways to produce schedules more complex than would be possible with any single built-in trigger.

API

class apscheduler.triggers.combining.AndTrigger(triggers, jitter=None)

Always returns the earliest next fire time that all the given triggers can agree on. The trigger is considered to be finished when any of the given triggers has finished its schedule.

Trigger alias: and

Parameters:
  • triggers (list) – triggers to combine
  • jitter (int|None) – advance or delay the job execution by jitter seconds at most.
class apscheduler.triggers.combining.OrTrigger(triggers, jitter=None)

Always returns the earliest next fire time produced by any of the given triggers. The trigger is considered finished when all the given triggers have finished their schedules.

Trigger alias: or

Parameters:
  • triggers (list) – triggers to combine
  • jitter (int|None) – advance or delay the job execution by jitter seconds at most.

Note

Triggers that depends on the previous fire time, such as the interval trigger, may seem to behave strangely since they are always passed the previous fire time produced by any of the given triggers.

Examples

Run job_function every 2 hours, but only on Saturdays and Sundays:

from apscheduler.triggers.combining import AndTrigger
from apscheduler.triggers.interval import IntervalTrigger
from apscheduler.triggers.cron import CronTrigger


trigger = AndTrigger([IntervalTrigger(hours=2),
                      CronTrigger(day_of_week='sat,sun')])
scheduler.add_job(job_function, trigger)

Run job_function every Monday at 2pm and every Tuesday at 3pm:

trigger = OrTrigger([CronTrigger(day_of_week='mon', hour=2),
                     CronTrigger(day_of_week='tue', hour=3)])
scheduler.add_job(job_function, trigger)