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.

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

Bases: BaseCombiningTrigger

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

Warning

This trigger should only be used to combine triggers that fire on specific times of day, such as CronTrigger and class:~apscheduler.triggers.calendarinterval.CalendarIntervalTrigger. Attempting to use it with IntervalTrigger will likely result in the scheduler hanging as it tries to find a fire time that matches exactly between fire times produced by all the given triggers.

Parameters:
  • triggers (list) – triggers to combine

  • jitter (int|None) – delay the job execution by jitter seconds at most

get_next_fire_time(previous_fire_time, now)

Returns the next datetime to fire on, If no such datetime can be calculated, returns None.

Parameters:
class apscheduler.triggers.combining.BaseCombiningTrigger(triggers, jitter=None)

Bases: BaseTrigger

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

Bases: BaseCombiningTrigger

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) – 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.

get_next_fire_time(previous_fire_time, now)

Returns the next datetime to fire on, If no such datetime can be calculated, returns None.

Parameters:

API

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

Bases: BaseCombiningTrigger

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

Warning

This trigger should only be used to combine triggers that fire on specific times of day, such as CronTrigger and class:~apscheduler.triggers.calendarinterval.CalendarIntervalTrigger. Attempting to use it with IntervalTrigger will likely result in the scheduler hanging as it tries to find a fire time that matches exactly between fire times produced by all the given triggers.

Parameters:
  • triggers (list) – triggers to combine

  • jitter (int|None) – delay the job execution by jitter seconds at most

get_next_fire_time(previous_fire_time, now)

Returns the next datetime to fire on, If no such datetime can be calculated, returns None.

Parameters:
class apscheduler.triggers.combining.OrTrigger(triggers, jitter=None)

Bases: BaseCombiningTrigger

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) – 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.

get_next_fire_time(previous_fire_time, now)

Returns the next datetime to fire on, If no such datetime can be calculated, returns None.

Parameters:

Examples

Run job_function every 3 days (at midnight), but only when that date lands on on a Saturday or Sunday:

from apscheduler.triggers.combining import AndTrigger
from apscheduler.triggers.calendarinterval import CalendarIntervalTrigger
from apscheduler.triggers.cron import CronTrigger


trigger = AndTrigger([CalendarIntervalTrigger(days=3),
                      CronTrigger(day_of_week='sat,sun')])
scheduler.add_job(job_function, trigger)

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

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