mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-01 08:58:12 +08:00
* updated README
* both func and hook check for callable.
This commit is contained in:
@@ -16,8 +16,41 @@ Schedule the asynchronous execution of a function by calling `async` from within
|
||||
```python
|
||||
async(func,*args,hook=None,**kwargs)
|
||||
```
|
||||
The optional hook function gets the finished task object as its first argument after execution
|
||||
####Basic example
|
||||
```python
|
||||
from django_q import async
|
||||
|
||||
# math.copysign(2,-2)
|
||||
async('math.copysign', 2, -2)
|
||||
|
||||
# also
|
||||
from math import copysign
|
||||
|
||||
async(copysign, 2, -2)
|
||||
|
||||
```
|
||||
#### Result example
|
||||
```python
|
||||
from django_q import async, result
|
||||
|
||||
# create the task
|
||||
task_id = async('math.copysign', 2, -2)
|
||||
|
||||
# get the result
|
||||
task_result = result(task_id)
|
||||
|
||||
# result returns None if the task has not been executed yet
|
||||
# so it makes more sense to use a hook:
|
||||
from hooks import print_result
|
||||
|
||||
async('math.modf', 2.5, hook='hooks.print_result')
|
||||
|
||||
# hooks.py
|
||||
def print_result(task):
|
||||
print(task.result)
|
||||
|
||||
|
||||
```
|
||||
### Management commands
|
||||
|
||||
#### `qcluster`
|
||||
|
||||
Reference in New Issue
Block a user