Skip to content

Commit

Permalink
feat:rename *Job to *Task
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla committed Oct 8, 2023
1 parent 23bb2d5 commit 5b71106
Show file tree
Hide file tree
Showing 22 changed files with 555 additions and 440 deletions.
8 changes: 8 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
# Changelog

## v1.2.0 🌈

### 🚀 Features

- Rename `*Job` models to `*Task` to differentiate.


## v1.1.0 🌈

### 🚀 Features

- Enable using stats view using api token
- Reverted, active jobs are not marked as scheduled as there is currently no new job instance for them.

### 🐛 Bug Fixes

Expand Down
6 changes: 3 additions & 3 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ python manage.py rqworker queue1 queue2 queue3

## export

Export all scheduled jobs from django db to json/yaml format.
Export all scheduled tasks from django db to json/yaml format.

```shell
python manage.py export -o {yaml,json}
Expand All @@ -26,7 +26,7 @@ Result should be (for json):
[
{
"model": "ScheduledJob",
"name": "Scheduled Job 1",
"name": "Scheduled Task 1",
"callable": "scheduler.tests.test_job",
"callable_args": [
{
Expand All @@ -52,7 +52,7 @@ A json/yaml that was exported using the `export` command
can be imported to django.

- Specify the source file using `--filename` or take it from the standard input (default).
- Reset all scheduled jobs in the database before importing using `-r`/`--reset`.
- Reset all scheduled tasks in the database before importing using `-r`/`--reset`.
- Update existing jobs for names that are found using `-u`/`--update`.

```shell
Expand Down
32 changes: 21 additions & 11 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
---

A database backed async tasks scheduler for django.
This allows remembering scheduled jobs, their parameters, etc.
This allows remembering scheduled tasks, their parameters, etc.

## Terminology

Expand All @@ -17,7 +17,7 @@ This allows remembering scheduled jobs, their parameters, etc.
A queue of messages between processes (main django-app process and worker usually).
This is implemented in `rq` package.

* A queue contains multiple registries for scheduled jobs, finished jobs, failed jobs, etc.
* A queue contains multiple registries for scheduled tasks, finished jobs, failed jobs, etc.

### Worker

Expand All @@ -36,26 +36,26 @@ This is a sub-process of worker.
Once a worker listening to the queue becomes available,
the job will be executed

### Scheduled Job Execution
### Scheduled Task Execution

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

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

### Scheduled Job
### Scheduled Task

django models storing information about jobs. So it is possible to schedule using
django-admin and track their status.

There are 3 types of scheduled job.
There are 3 types of scheduled task.

* `Scheduled Job` - Run a job once, on a specific time (can be immediate).
* `Repeatable Job` - Run a job multiple times (limited number of times or infinite times) based on an interval
* `Cron Job` - Run a job multiple times (limited number of times or infinite times) based on a cron string
* `Scheduled Task` - Run a job once, on a specific time (can be immediate).
* `Repeatable Task` - Run a job multiple times (limited number of times or infinite times) based on an interval
* `Cron Task` - Run a job multiple times (limited number of times or infinite times) based on a cron string

Scheduled jobs are scheduled when the django application starts, and after a scheduled job is executed.
Scheduled jobs are scheduled when the django application starts, and after a scheduled task is executed.

## Scheduler sequence diagram

Expand All @@ -65,12 +65,22 @@ sequenceDiagram
box Worker
participant scheduler as Scheduler Process
end
box DB
participant db as Database
end
box Redis queue
participant queue as Queue
participant schedule as Queue scheduled jobs
participant schedule as Queue scheduled tasks
end
loop Scheduler process - loop forever
scheduler ->> schedule: check whether there are jobs that should be scheduled for execution
note over scheduler,schedule: Database interaction
scheduler ->> db: Check for enabled tasks that should be scheduled
critical There are tasks to be scheduled
scheduler ->> schedule: Create a job for task that should be scheduled
end
note over scheduler,schedule: Redis queues interaction
scheduler ->> schedule: check whether there are scheduled tasks that should be executed
critical there are jobs that are scheduled to be executed
scheduler ->> schedule: remove jobs to be scheduled
scheduler ->> queue: enqueue jobs to be executed
Expand Down
18 changes: 10 additions & 8 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ RQ = {

* Sign in to the Django Admin site (e.g., http://localhost:8000/admin/) and locate the
**Tasks Scheduler** section.
* Click on the **Add** link for the type of job you want to add (`Scheduled Job` - run once, `Repeatable Job` - run
multiple times, `Cron Job` - Run based on cron schedule).
* Click on the **Add** link for the type of job you want to add (`Scheduled Task` - run once, `Repeatable Task` - run
multiple times, `Cron Task` - Run based on cron schedule).
* Enter a unique name for the job in the **Name** field.
* In the **Callable** field, enter a Python dot notation path to the method that defines the job. For the example
above, that would be `myapp.jobs.count`
Expand Down Expand Up @@ -83,11 +83,11 @@ calculated in runtime.

![](media/add-args.jpg)

### Scheduled Job - run once
### Scheduled Task - run once

No additional steps required.

### Repeatable Job - Run a job multiple time based on interval
### Repeatable Task - Run a job multiple time based on interval

Additional fields required:

Expand All @@ -96,19 +96,19 @@ Additional fields required:
* In the **Repeat** field, enter the number of time the job is to be run. Leaving the field empty, means the job will
be scheduled to run forever.

### Cron Job - Run a job multiple time based on cron
### Cron Task - Run a job multiple time based on cron

Additional fields required:

* In the **Repeat** field, enter the number of time the job is to be run. Leaving the field empty, means the job will be
scheduled to run forever.
* In the **cron string** field, enter a cron string describing how often the job should run.

### Scheduled Job - run once
### Scheduled Task - run once

No additional steps required.

### Repeatable Job - Run a job multiple time based on interval
### Repeatable Task - Run a job multiple time based on interval

Additional fields required:

Expand All @@ -117,7 +117,7 @@ Additional fields required:
* In the **Repeat** field, enter the number of time the job is to be run. Leaving the field empty, means the job will
be scheduled to run forever.

### Cron Job - Run a job multiple time based on cron
### Cron Task - Run a job multiple time based on cron

Additional fields required:

Expand Down Expand Up @@ -177,12 +177,14 @@ WantedBy = multi-user.target
```

After you are done editing the file, reload the settings and start the new workers:

```shell
sudo systemctl daemon-reload
sudo systemctl start rqworker@{1..3}
```

You can target a specific worker using its number:

```shell
sudo systemctl stop rqworker@2
```
Loading

0 comments on commit 5b71106

Please sign in to comment.