Quellcode durchsuchen

Mention time zones in the periodic task guide

Ask Solem vor 12 Jahren
Ursprung
Commit
d0e2c5d907
1 geänderte Dateien mit 34 neuen und 0 gelöschten Zeilen
  1. 34 0
      docs/userguide/periodic-tasks.rst

+ 34 - 0
docs/userguide/periodic-tasks.rst

@@ -22,6 +22,38 @@ at a time, otherwise you would end up with duplicate tasks.  Using
 a centralized approach means the schedule does not have to be synchronized,
 and the service can operate without using locks.
 
+.. _beat-timezones:
+
+Time Zones
+==========
+
+The periodic task schedules uses the UTC time zone by default,
+but you can change the time zone used using the :setting:`CELERY_TIMEZONE`
+setting.
+
+If you use a time zone other than UTC it's recommended to install the
+:mod:`pytz` library as this can improve the accuracy and keep your timezone
+specifications up to date:
+
+.. code-block:: bash
+
+    $ pip install -U pytz
+
+
+An example time zone could be `Europe/London`:
+
+.. code-block:: python
+
+    CELERY_TIMEZONE = 'Europe/London'
+
+.. admonition:: Changing the time zone
+
+The default scheduler (storing the schedule in the :file:`celerybeat-schedule`
+file) will automatically detect that the timezone has changed, and so will
+reset the schedule itself, but other schedulers may not be so smart (e.g. the
+Django database scheduler) and in that case you will have to reset the
+schedule manually.
+
 .. _beat-entries:
 
 Entries
@@ -44,6 +76,8 @@ Example: Run the `tasks.add` task every 30 seconds.
         },
     }
 
+    CELERY_TIMEZONE = 'UTC'
+
 
 Using a :class:`~datetime.timedelta` for the schedule means the task will
 be executed 30 seconds after `celery beat` starts, and then every 30 seconds