Debian Codegraph @

docs/modules/triggers/calendarinterval.rst

raw
1 :mod:`apscheduler.triggers.calendarinterval`
2 ============================================
3
4 .. automodule:: apscheduler.triggers.calendarinterval
5
6 API
7 ---
8
9 Trigger alias for :meth:`~apscheduler.schedulers.base.BaseScheduler.add_job`:
10 ``calendarinterval``
11
12 .. autoclass:: CalendarIntervalTrigger
13 :show-inheritance:
14
15 Examples
16 --------
17
18 ::
19
20 from datetime import datetime
21
22 from apscheduler.schedulers.blocking import BlockingScheduler
23
24
25 def job_function():
26 print("Hello World")
27
28 sched = BlockingScheduler()
29
30 # Schedule job_function to be called every two months at 16:49:00
31 sched.add_job(job_function, 'calendarinterval', months=2, hour=16, minute=49)
32
33 sched.start()
34
35
36 You can use ``start_date`` and ``end_date`` to limit the total time in which the
37 schedule runs::
38
39 # The same as before, but starts on 2010-10-10 and stops on 2014-06-15
40 sched.add_job(
41 job_function,
42 'calendarinterval',
43 months=2,
44 hour=16,
45 minute=49,
46 start_date='2010-10-10',
47 end_date='2014-06-15'
48 )
49
50
51 The ``jitter`` option enables you to add a random component to the execution time.
52 This might be useful if you have multiple servers and don't want them to run a job at
53 the exact same moment or if you want to prevent multiple jobs with similar options from
54 always running concurrently::
55
56 # Run `job_function` every two months with an extra delay picked randomly between 0
57 # and 120 seconds
58 sched.add_job(job_function, 'calendarinterval', months=2, jitter=120)