Skip to content

Commit

Permalink
Updated the AndTrigger example to use CalendarIntervalTrigger instead…
Browse files Browse the repository at this point in the history
… of IntervalTrigger
  • Loading branch information
agronholm committed Nov 23, 2024
1 parent bf8878a commit 01217bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 9 additions & 0 deletions apscheduler/triggers/combining.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ class AndTrigger(BaseCombiningTrigger):
Trigger alias: ``and``
.. warning:: This trigger should only be used to combine triggers that fire on
specific times of day, such as
:class:`~apscheduler.triggers.cron.CronTrigger` and
class:`~apscheduler.triggers.calendarinterval.CalendarIntervalTrigger`.
Attempting to use it with
:class:`~apscheduler.triggers.interval.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.
:param list triggers: triggers to combine
:param int|None jitter: delay the job execution by ``jitter`` seconds at most
"""
Expand Down
9 changes: 5 additions & 4 deletions docs/modules/triggers/combining.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ API
Examples
--------

Run ``job_function`` every 2 hours, but only on Saturdays and Sundays::
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.interval import IntervalTrigger
from apscheduler.triggers.calendarinterval import CalendarIntervalTrigger
from apscheduler.triggers.cron import CronTrigger


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

Run ``job_function`` every Monday at 2am and every Tuesday at 3pm::
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)])
Expand Down

0 comments on commit 01217bc

Please sign in to comment.