mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-06 01:08:12 +08:00
docs: describes the new group options
This commit is contained in:
+5
-1
@@ -51,7 +51,7 @@ Reference
|
|||||||
.. py:function:: schedule(func, *args, hook=None, schedule_type='O', repeats=-1, next_run=now() , **kwargs)
|
.. py:function:: schedule(func, *args, hook=None, schedule_type='O', repeats=-1, next_run=now() , **kwargs)
|
||||||
|
|
||||||
Creates a schedule
|
Creates a schedule
|
||||||
|
:param str name: A sensible name for your schedule
|
||||||
:param str func: the function to schedule. Dotted strings only.
|
:param str func: the function to schedule. Dotted strings only.
|
||||||
:param args: arguments for the scheduled function.
|
:param args: arguments for the scheduled function.
|
||||||
:param str hook: optional result hook function. Dotted strings only.
|
:param str hook: optional result hook function. Dotted strings only.
|
||||||
@@ -68,6 +68,10 @@ Reference
|
|||||||
|
|
||||||
Primary key
|
Primary key
|
||||||
|
|
||||||
|
.. py:attribute:: name
|
||||||
|
|
||||||
|
A name for your schedule. Tasks created by this schedule will assume this as their group id.
|
||||||
|
|
||||||
.. py:attribute:: func
|
.. py:attribute:: func
|
||||||
|
|
||||||
The function to be scheduled
|
The function to be scheduled
|
||||||
|
|||||||
+62
-9
@@ -31,6 +31,31 @@ Use :func:`async` from your code to quickly offload tasks to the :class:`Cluster
|
|||||||
def print_result(task):
|
def print_result(task):
|
||||||
print(task.result)
|
print(task.result)
|
||||||
|
|
||||||
|
Groups
|
||||||
|
------
|
||||||
|
You can group together results by passing :func:`async` the optional `group` keyword:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
from django_q import async, result_group
|
||||||
|
|
||||||
|
for i in range(4):
|
||||||
|
async('math.modf', i, group='modf')
|
||||||
|
|
||||||
|
# after the tasks have finished you can get the group results
|
||||||
|
result = result_group('modf')
|
||||||
|
print(result)
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
[(0.0, 0.0), (0.0, 1.0), (0.0, 2.0), (0.0, 3.0)]
|
||||||
|
|
||||||
|
Take care that you haven't limited your results database too much and that the group identifier is unique for each run.
|
||||||
|
Instead of :func:`result_group` you can also use :func:`fetch_group` to return a list of :class:`Task` objects.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
Tasks created by a schedule, will use the schedules name as their group id.
|
||||||
|
|
||||||
Synchronous testing
|
Synchronous testing
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
@@ -78,19 +103,19 @@ When you are making individual calls to :func:`async` a lot though, it can help
|
|||||||
Reference
|
Reference
|
||||||
---------
|
---------
|
||||||
|
|
||||||
.. py:function:: async(func, *args, hook=None, timeout=None, sync=False, redis=None, **kwargs)
|
.. py:function:: async(func, *args, hook=None, group=None, timeout=None,\
|
||||||
|
sync=False, redis=None, **kwargs)
|
||||||
|
|
||||||
Puts a task in the cluster queue
|
Puts a task in the cluster queue
|
||||||
|
|
||||||
:param func: The task function to execute
|
:param object func: The task function to execute
|
||||||
:param args: The arguments for the task function
|
:param tuple args: The arguments for the task function
|
||||||
:type func: object
|
:param object hook: Optional function to call after execution
|
||||||
:param hook: Optional function to call after execution
|
:param str group: An optional group identifier
|
||||||
:type hook: object
|
|
||||||
:param int timeout: Overrides global cluster :ref:`timeout`.
|
:param int timeout: Overrides global cluster :ref:`timeout`.
|
||||||
:param bool sync: If set to True, async will simulate a task execution
|
:param bool sync: If set to True, async will simulate a task execution
|
||||||
:param redis: Optional redis connection
|
:param redis: Optional redis connection
|
||||||
:param kwargs: Keyword arguments for the task function
|
:param dict kwargs: Keyword arguments for the task function
|
||||||
:returns: The uuid of the task
|
:returns: The uuid of the task
|
||||||
:rtype: str
|
:rtype: str
|
||||||
|
|
||||||
@@ -106,13 +131,29 @@ Reference
|
|||||||
Returns a previously executed task
|
Returns a previously executed task
|
||||||
|
|
||||||
:param str name: the uuid or name of the task
|
:param str name: the uuid or name of the task
|
||||||
:returns: The task
|
:returns: The task if any
|
||||||
:rtype: Task
|
:rtype: Task
|
||||||
|
|
||||||
.. versionchanged:: 0.2.0
|
.. versionchanged:: 0.2.0
|
||||||
|
|
||||||
Renamed from get_task
|
Renamed from get_task
|
||||||
|
|
||||||
|
.. py:function:: result_group(group_id)
|
||||||
|
|
||||||
|
Returns the results of a task group
|
||||||
|
|
||||||
|
:param str group_id: the group identifier
|
||||||
|
:returns: a list of results
|
||||||
|
:rtype: list
|
||||||
|
|
||||||
|
.. py:function:: fetch_group(group_id)
|
||||||
|
|
||||||
|
Returns a list of tasks in a group
|
||||||
|
|
||||||
|
:param str group_id: the group identifier
|
||||||
|
:returns: a list of Tasks
|
||||||
|
:rtype: list
|
||||||
|
|
||||||
.. py:class:: Task
|
.. py:class:: Task
|
||||||
|
|
||||||
Database model describing an executed task
|
Database model describing an executed task
|
||||||
@@ -174,7 +215,19 @@ Reference
|
|||||||
|
|
||||||
.. py:classmethod:: get_result(task_id)
|
.. py:classmethod:: get_result(task_id)
|
||||||
|
|
||||||
Get a result directly by task uuid or name
|
Gets a result directly by task uuid or name.
|
||||||
|
|
||||||
|
.. py:classmethod:: get_result_group(group_id)
|
||||||
|
|
||||||
|
Returns a list of results from a task group.
|
||||||
|
|
||||||
|
.. py:classmethod:: get_task(task_id)
|
||||||
|
|
||||||
|
Fetches a single task object by uuid or name.
|
||||||
|
|
||||||
|
.. py:classmethod:: get_task_group(group_id)
|
||||||
|
|
||||||
|
Gets a queryset of tasks with this group id.
|
||||||
|
|
||||||
.. py:class:: Success
|
.. py:class:: Success
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user