mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-03 14:48:12 +08:00
* updated README
* both func and hook check for callable.
This commit is contained in:
+37
-2
@@ -25,8 +25,43 @@ from within your Django project.
|
||||
|
||||
async(func,*args,hook=None,**kwargs)
|
||||
|
||||
The optional hook function gets the finished task object as its first
|
||||
argument after execution
|
||||
Basic example
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
.. code:: 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
|
||||
^^^^^^^^^^^^^^
|
||||
|
||||
.. code:: 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
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Reference in New Issue
Block a user