You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+50-5Lines changed: 50 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,21 +8,60 @@ Asynchronous tasks are run via a *job queue*. This system is designed to support
8
8
9
9
This is not yet production-ready, and the API is liable to change. Use at your own risk.
10
10
11
-
### Terminology
11
+
##Getting Started
12
12
13
-
#### Job
13
+
### Describe your job
14
+
15
+
In e.g. project.common.jobs:
16
+
17
+
```python
18
+
import time
19
+
20
+
defmy_task(job):
21
+
logger.info("Working hard...")
22
+
time.sleep(10)
23
+
logger.info("Job's done!")
24
+
```
25
+
26
+
### Set up your job
27
+
28
+
In project.settings:
29
+
30
+
```python
31
+
JOBS= {
32
+
'my_job': ['project.common.jobs.my_task'],
33
+
}
34
+
```
35
+
36
+
### Start the worker
37
+
38
+
In another terminal:
39
+
40
+
`python manage.py worker`
41
+
42
+
### Create a job
43
+
44
+
Using the name you configured for your job in your settings, create an instance of Job.
45
+
46
+
```python
47
+
Job.objects.create(name='my_job')
48
+
```
49
+
50
+
## Terminology
51
+
52
+
### Job
14
53
15
54
The top-level abstraction of a standalone piece of work. Jobs are stored in the database (ie they are represented as Django model instances).
16
55
17
-
####Task
56
+
### Task
18
57
19
58
Jobs are processed to completion by *tasks*. These are simply Python functions, which must take a single argument - the `Job` instance being processed. A single job will often require processing by more than one task to be completed fully. Creating the task functions is the responsibility of the developer. For example:
20
59
21
60
def my_task(job):
22
61
logger.info("Doing some hard work")
23
62
do_some_hard_work()
24
63
25
-
####Workspace
64
+
### Workspace
26
65
27
66
The *workspace* is an area that tasks within a single job can use to communicate with each other. It is implemented as a Python dictionary, available on the `job` instance passed to tasks as `job.workspace`. The initial workspace of a job can be empty, or can contain some parameters that the tasks require (for example, API access tokens, account IDs etc). A single task can edit the workspace, and the modified workspace will be passed on to the next task in the sequence. For example:
28
67
@@ -32,7 +71,13 @@ The *workspace* is an area that tasks within a single job can use to communicate
A *worker process* is a long-running process, implemented as a Django management command, which is responsible for executing the tasks associated with a job. There may be many worker processes running concurrently in the final system. Worker processes wait for a new job to be created in the database, and call the each associated task in the correct sequeunce.. A worker can be started using `python manage.py worker`, and a single worker instance is included in the development `procfile`.
0 commit comments