Skip to content

Commit f4f7d75

Browse files
authored
feat:unify models to one model instead of 3 separate ones (#176)
1 parent 957d4e1 commit f4f7d75

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3246
-674
lines changed

Diff for: docs/changelog.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## v3.0.0 🌈
4+
5+
### Breaking Changes
6+
7+
- Renamed `REDIS_CLIENT_KWARGS` configuration to `CLIENT_KWARGS`.
8+
9+
### 🚀 Features
10+
11+
- Created a new `Task` model representing all kind of scheduled tasks.
12+
- In future versions, `CronTask`, `ScheduledTask` and `RepeatableTask` will be removed.
13+
- `Task` model has a `task_type` field to differentiate between the types of tasks.
14+
- Old tasks in the database will be migrated to the new `Task` model automatically.
15+
316
## v2.1.1 🌈
417

518
### 🐛 Bug Fixes

Diff for: docs/configuration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ SCHEDULER_QUEUES = {
2020
'USERNAME': 'some-user',
2121
'PASSWORD': 'some-password',
2222
'DEFAULT_TIMEOUT': 360,
23-
'REDIS_CLIENT_KWARGS': { # Eventual additional Redis connection arguments
23+
'CLIENT_KWARGS': { # Eventual additional Redis connection arguments
2424
'ssl_cert_reqs': None,
2525
},
2626
'TOKEN_VALIDATION_METHOD': None, # Method to validate auth-header

Diff for: docs/index.md

+40-25
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,44 @@
11
# Django tasks Scheduler
22

3-
[![Django CI][1]][2]
4-
![badge][3]
5-
[![badge][4]][5]
3+
[![Django CI][badge]][2]
4+
![badge][coverage]
5+
[![badge][pypi-downloads]][pypi]
66

77
---
88

99
A database backed asynchronous tasks scheduler for django.
1010
This allows remembering scheduled tasks, their parameters, etc.
1111

12+
!!! Important
13+
Version 3.0.0 introduced a major design change. Instead of three separate models, there is one new `Task` model.
14+
The goal is to simplify.
15+
Make sure to follow [the migration guide](migrate_to_v3.md)
16+
17+
1218
## Terminology
1319

20+
### Scheduled Task
21+
22+
Starting v3.0.0, django-tasks-scheduler is using a single `Task` model with different task types, the task types are:
23+
24+
- `ONCE` - Run the task once at a scheduled time.
25+
- `REPEATABLE` - Run the task multiple times (limited number of times or infinite times) based on a time interval.
26+
- `CRON` - Run a task indefinitely based on a cron string schedule.
27+
28+
This enables having one admin view for all scheduled tasks, and having one table in the database to maintain the task
29+
reduces the number of overall queries.
30+
An `Task` instance contains all relevant information about a task to enable the users to schedule using django-admin and
31+
track their status.
32+
33+
Previously, there were three different models for ScheduledTask. These exist for legacy purposes and are scheduled to
34+
be removed.
35+
36+
* `Scheduled Task` - Run a task once, on a specific time (can be immediate).
37+
* `Repeatable Task` - Run a task multiple times (limited number of times or infinite times) based on an interval
38+
* `Cron Task` - Run a task multiple times (limited number of times or infinite times) based on a cron string
39+
40+
Scheduled tasks are scheduled when the django application starts, and after a scheduled task is executed.
41+
1442
### Queue
1543

1644
A queue of messages between processes (main django-app process and worker usually).
@@ -34,27 +62,14 @@ This is a subprocess of worker.
3462

3563
Once a worker listening to the queue becomes available, the job will be executed
3664

37-
### Scheduled Task Execution
65+
### Scheduled Job Execution
3866

3967
A scheduler checking the queue periodically will check whether the time the job should be executed has come, and if so,
4068
it will queue it.
4169

4270
* A job is considered scheduled if it is queued to be executed, or scheduled to be executed.
4371
* If there is no scheduler, the job will not be queued to run.
4472

45-
### Scheduled Task
46-
47-
django models storing information about jobs. So it is possible to schedule using
48-
django-admin and track their status.
49-
50-
There are three types of ScheduledTask.
51-
52-
* `Scheduled Task` - Run a job once, on a specific time (can be immediate).
53-
* `Repeatable Task` - Run a job multiple times (limited number of times or infinite times) based on an interval
54-
* `Cron Task` - Run a job multiple times (limited number of times or infinite times) based on a cron string
55-
56-
Scheduled jobs are scheduled when the django application starts, and after a scheduled task is executed.
57-
5873
## Scheduler sequence diagram
5974

6075
```mermaid
@@ -121,24 +136,24 @@ sequenceDiagram
121136

122137
## Reporting issues or Features requests
123138

124-
Please report issues via [GitHub Issues][6] .
139+
Please report issues via [GitHub Issues][issues] .
125140

126141
---
127142

128143
## Acknowledgements
129144

130-
A lot of django-admin views and their tests were adopted from [django-rq][7].
145+
A lot of django-admin views and their tests were adopted from [django-rq][django-rq].
131146

132-
[1]:https://github.com/django-commons/django-tasks-scheduler/actions/workflows/test.yml/badge.svg
147+
[badge]:https://github.com/django-commons/django-tasks-scheduler/actions/workflows/test.yml/badge.svg
133148

134149
[2]:https://github.com/django-commons/django-tasks-scheduler/actions/workflows/test.yml
135150

136-
[3]:https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/cunla/b756396efb895f0e34558c980f1ca0c7/raw/django-tasks-scheduler-4.json
151+
[coverage]:https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/cunla/b756396efb895f0e34558c980f1ca0c7/raw/django-tasks-scheduler-4.json
137152

138-
[4]:https://img.shields.io/pypi/dm/django-tasks-scheduler
153+
[pypi-downloads]:https://img.shields.io/pypi/dm/django-tasks-scheduler
139154

140-
[5]:https://pypi.org/project/django-tasks-scheduler/
155+
[pypi]:https://pypi.org/project/django-tasks-scheduler/
141156

142-
[6]:https://github.com/django-commons/django-tasks-scheduler/issues
157+
[issues]:https://github.com/django-commons/django-tasks-scheduler/issues
143158

144-
[7]:https://github.com/rq/django-rq
159+
[django-rq]:https://github.com/rq/django-rq

Diff for: docs/installation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
'USERNAME': 'some-user',
2727
'PASSWORD': 'some-password',
2828
'DEFAULT_TIMEOUT': 360,
29-
'REDIS_CLIENT_KWARGS': { # Eventual additional Redis connection arguments
29+
'CLIENT_KWARGS': { # Eventual additional Redis connection arguments
3030
'ssl_cert_reqs': None,
3131
},
3232
},

Diff for: docs/migrate_to_v3.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Migration from v2 to v3
2+
=======================
3+
4+
Version 3.0.0 introduced a major design change. Instead of three separate models, there is one new `Task` model. The
5+
goal is to have one centralized admin view for all your scheduled tasks, regardless of the scheduling type.
6+
7+
You need to migrate the scheduled tasks using the old models (`ScheduledTask`, `RepeatableTask`, `CronTask`) to the new
8+
model. It can be done using the export/import commands provided.
9+
10+
After upgrading to django-tasks-scheduler v3.0.0, you will notice you are not able to create new scheduled tasks in the
11+
old models, that is intentional. In the next version of django-tasks-scheduler (v3.1), the old models will be deleted,
12+
so make sure you migrate your old models.
13+
14+
!!! Note
15+
While we tested different scenarios heavily and left the code for old tasks, we could not account for all different
16+
use cases, therefore, please [open an issue][issues] if you encounter any.
17+
18+
There are two ways to migrate your existing scheduled tasks:
19+
20+
# Using the admin views of the old models
21+
22+
If you go to the admin view of the old models, you will notice there is a new action in the actions drop down menu for
23+
migrating the selected tasks. Use it, and you will also have a link to the new task to compare the migration result.
24+
25+
Note once you migrate using this method, the old task will be disabled automatically.
26+
27+
# Export/Import management commands
28+
29+
Run in your project directory:
30+
31+
```shell
32+
python manage.py export > scheduled_tasks.json
33+
python manage.py import --filename scheduled_tasks.json
34+
```
35+
36+
[issues]: https://github.com/django-commons/django-tasks-scheduler/issues

Diff for: mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ theme:
101101

102102
nav:
103103
- Home: index.md
104+
- Migrate v2 to v3: migrate_to_v3.md
104105
- Installation: installation.md
105106
- Configuration: configuration.md
106107
- Usage: usage.md

0 commit comments

Comments
 (0)