summaryrefslogtreecommitdiff
path: root/docs/modules/triggers/date.rst
blob: f784e38110a0b71adbdba3268e0db5dde8238e10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
:mod:`apscheduler.triggers.date`
================================

.. automodule:: apscheduler.triggers.date

API
---

Trigger alias for :meth:`~apscheduler.schedulers.base.BaseScheduler.add_job`: ``date``

.. autoclass:: DateTrigger
    :show-inheritance:


Introduction
------------

This is the simplest possible method of scheduling a job. It schedules a job to be executed once at the specified time.
It is APScheduler's equivalent to the UNIX "at" command.

The ``run_date`` can be given either as a date/datetime object or text (in the
`ISO 8601 <https://en.wikipedia.org/wiki/ISO_8601>`_ format).


Examples
--------

::

    from datetime import date

    from apscheduler.scheduler import BlockingScheduler


    sched = BlockingScheduler()

    def my_job(text):
        print(text)

    # The job will be executed on November 6th, 2009
    sched.add_job(my_job, 'date', run_date=date(2009, 11, 6), args=['text'])

    sched.start()


You can specify the exact time when the job should be run::

    # The job will be executed on November 6th, 2009 at 16:30:05
    sched.add_job(my_job, 'date', run_date=datetime(2009, 11, 6, 16, 30, 5), args=['text'])


The run date can be given as text too::

    sched.add_job(my_job, 'date', run_date='2009-11-06 16:30:05', args=['text'])

To add a job to be run immediately::

    # The 'date' trigger is implicit
    sched.add_job(my_job, args=['text'])

.. note:: Jobs added this way (no trigger specified) never time out (i.e. ``misfire grace period`` is set to
   ``None`` by default.