docs: added section about scheduling management commands

This commit is contained in:
Ilan Steemers
2015-07-10 17:36:18 +02:00
parent 2c58262b17
commit 13bbf3dcc4

View File

@@ -1,6 +1,9 @@
Schedules
=========
Schedule
--------
Schedules are regular Django models. You can manage them through the :ref:`admin_page` or directly from your code with the :func:`schedule` function or the :class:`Schedule` model:
.. code:: python
@@ -22,6 +25,26 @@ Schedules are regular Django models. You can manage them through the :ref:`admin
schedule_type=Schedule.DAILY
)
Management Commands
-------------------
If you want to schedule regular Django management commands, you can use the :mod:`django.core.management` module to make a wrapper function which you can schedule in Django Q::
# tasks.py
from django.core import management
# wrapping `manage.py clearsessions`
def clear_sessions_command():
return management.call_command('clearsessions')
# now you can schedule it to run every hour
from django_q import schedule
schedule('tasks.clear_sessions_command', schedule_type='H')
Reference
---------
@@ -123,4 +146,4 @@ Reference
.. py:attribute:: YEARLY
`'Y'` only runs once a year. The same caution as with months apply;
If you set this to february 29th, it will run on february 28th in the following years.
If you set this to february 29th, it will run on february 28th in the following years.