mirror of
https://github.com/django-q2/django-q2.git
synced 2026-09-15 13:37:56 +08:00
docs: added section about scheduling management commands
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user