Skip to content

Commit 99aea41

Browse files
committed
📖 createtask docs
1 parent 8c804f4 commit 99aea41

File tree

6 files changed

+93
-2
lines changed

6 files changed

+93
-2
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Features
3030
- Authorize against **Active Directory** using `ldap3 <https://ldap3.readthedocs.io/en/latest/>`_ package
3131
- Manage **LDAP Connections** for easy integrations
3232
- Debug using `django-debug-toolbar <https://django-debug-toolbar.readthedocs.io/en/latest/>`_
33+
- **NEW** Create Task Schedulers for Django management commands
3334

3435
Quick Start
3536
-----------

docs/source/howto/create_tasks.rst

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
Create Task Scheduler Jobs
3+
==========================
4+
5+
It is usually necessary to **execute tasks** from you project on a schedule.
6+
This module has a shortcut to create scheduled jobs for **Django management commands** in the **Windows Task Scheduler**.
7+
8+
.. warning::
9+
This feature requires the installation of the ``pywin32`` module.
10+
Install it with ``pip install pywin32``
11+
12+
Create a task
13+
-------------
14+
15+
Creating a new task is done with the ``createtask`` command.
16+
17+
For example, lets say you want to run the following command every hour::
18+
19+
$ py manage.py say_hello --new-users
20+
21+
You can create a schedule with this command::
22+
23+
$ py manage.py createtask "say_hello --new-users" -i hours=1
24+
25+
Now the following command will be executed every hour by the Windows Task Scheduler.
26+
27+
Using predefined tasks
28+
----------------------
29+
30+
Included with this module are some **predefined tasks** for some Django and Third-Party app management commands.
31+
Those commands can be created using the ``--predefined`` or ``-p`` argument
32+
33+
:clearsessions:
34+
Clear expired sessions from database, once a week::
35+
36+
$ py manage.py createtask clearsessions -p
37+
38+
.. seealso::
39+
See more at https://docs.djangoproject.com/en/3.1/ref/django-admin/#django-admin-clearsessions
40+
41+
:clean_duplicate_history:
42+
Clean duplicate history records from all models with history every 3 hours (from django-simple-history)::
43+
44+
$ py manage.py createtask clean_duplicate_history -p
45+
46+
:clean_old_history:
47+
Clean history records older then 30 days from all models with history every day (from django-simple-history)::
48+
49+
$ py manage.py createtask clean_old_history -p
50+
51+
52+
.. seealso::
53+
See more at https://django-simple-history.readthedocs.io/en/latest/utils.html#utils
54+
55+
:process_tasks:
56+
Worker for background tasks processing (from django-background-tasks)::
57+
58+
$ py manage.py createtask process_tasks -p
59+
60+
61+
You can also create **multiple workers** by specifying different names with ``--name`` argument.
62+
63+
.. seealso::
64+
See more at https://django-background-tasks.readthedocs.io/en/latest/#running-tasks

docs/source/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Features
1515
- Authorize against Active Directory using `ldap3 <https://ldap3.readthedocs.io/en/latest/>`_ package
1616
- Manage LDAP connections for easy integrations
1717
- Debug using `django-debug-toolbar <https://django-debug-toolbar.readthedocs.io/en/latest/>`_
18+
- **NEW** Create Task Schedulers for Django management commands
1819

1920
.. toctree::
2021
:maxdepth: 1
@@ -30,6 +31,7 @@ Features
3031
:caption: How-to Guides
3132

3233
howto/serve_static
34+
howto/create_tasks
3335
howto/custom_user_fields
3436
howto/using_ldap_manager
3537
howto/manage_secrets

docs/source/reference/change_log.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Change Log
88
Release date: coming soon
99

1010
- **ADDED**: LDAPUserManager for manually creating users from LDAP.
11+
- **ADDED**: ``createtask`` management command for creating Task Scheduler jobs.
1112
- **IMPROVED**: LDAP Settings for Group Membership check propagate to one another.
1213
- **MODIFIED**: Increased the default ``WAUTH_RESYNC_DELTA`` to every 1 day.
1314

docs/source/reference/management_commands.rst

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,27 @@ Arguments
2121

2222
.. warning::
2323
In order for the ``web.config`` files to work correctly, you will need to **unlock** some IIS Configuration Section.
24-
See the **Install and Setup IIS** section at :doc:`../installation/installation` docs.
24+
See the **Install and Setup IIS** section at :doc:`../installation/installation` docs.
25+
26+
createtask
27+
----------
28+
29+
Add a management command to Windows Task Scheduler.
30+
31+
Arguments
32+
* **command** Management command, wrapped with "command".
33+
* **--predefined**, **-p** Create from a predefined task.
34+
* **--name**, **-n** Task name.
35+
* **--desc**, **-d** Task description.
36+
* **--identity**, **-u** Task principal identity (default: "NT Authority\\LocalSystem").
37+
* **--folder**, **-f** Task folder location (default: Project's name).
38+
* **--interval**, **-i** Task execution interval as timedelta kwargs, e.g. "days=1,hours=12.5".
39+
* **--random**, **-r** Randomize execution time as timedelta kwargs, e.g. "days=1,hours=12.5".
40+
* **--timeout**, **-t** Execution time limit as timedelta kwargs, e.g. "days=1,hours=12.5" (default: 1 hour).
41+
* **--priority** Task priority https://docs.microsoft.com/en-us/windows/win32/taskschd/tasksettings-priority
42+
43+
Predefined tasks
44+
* **clearsessions** Clear sessions from database every week.
45+
* **clean_duplicate_history** Clean duplicate history records from all models with history every 3 hours (from django-simple-history).
46+
* **clean_old_history** Clean history records older then 30 days from all models with history every day (from django-simple-history).
47+
* **process_tasks** Worker for background tasks processing (from django-background-tasks).

windows_auth/management/commands/createtask.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Command(BaseCommand):
4646
def add_arguments(self, parser: CommandParser):
4747
parser.add_argument("command", help="Management command, wrapped with \"command\"")
4848
parser.add_argument("-p", "--predefined", action="store_true",
49-
help=f"Create a predefined task {tuple(PREDEFINED_TASKS.keys())}")
49+
help=f"Create from a predefined task {tuple(PREDEFINED_TASKS.keys())}")
5050
parser.add_argument("-n", "--name", type=str, help="Task name")
5151
parser.add_argument("-d", "--desc", type=str, default="", help="Task description")
5252
parser.add_argument("-u", "--identity", type=str, default=LOCAL_SERVICE, help="Task principle identity"),

0 commit comments

Comments
 (0)