mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-08 05:18:12 +08:00
docs: added info about the save override keyword
docs: added explanation of the `q_options` dict
This commit is contained in:
@@ -25,6 +25,13 @@ You can manage them through the :ref:`admin_page` or directly from your code wit
|
|||||||
schedule_type=Schedule.DAILY
|
schedule_type=Schedule.DAILY
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# In case you want to use async options
|
||||||
|
schedule('math.sqrt',
|
||||||
|
9,
|
||||||
|
hook='hooks.print_result',
|
||||||
|
q_options={'timeout': 30},
|
||||||
|
schedule_type=Schedule.HOURLY)
|
||||||
|
|
||||||
|
|
||||||
Management Commands
|
Management Commands
|
||||||
-------------------
|
-------------------
|
||||||
@@ -59,6 +66,7 @@ Reference
|
|||||||
:param str schedule_type: (O)nce, (H)ourly, (D)aily, (W)eekly, (M)onthly, (Q)uarterly, (Y)early or :attr:`Schedule.TYPE`
|
:param str schedule_type: (O)nce, (H)ourly, (D)aily, (W)eekly, (M)onthly, (Q)uarterly, (Y)early or :attr:`Schedule.TYPE`
|
||||||
:param int repeats: Number of times to repeat schedule. -1=Always, 0=Never, n =n.
|
:param int repeats: Number of times to repeat schedule. -1=Always, 0=Never, n =n.
|
||||||
:param datetime next_run: Next or first scheduled execution datetime.
|
:param datetime next_run: Next or first scheduled execution datetime.
|
||||||
|
:param dict q_options: async options to use for this schedule
|
||||||
:param kwargs: optional keyword arguments for the scheduled function.
|
:param kwargs: optional keyword arguments for the scheduled function.
|
||||||
|
|
||||||
.. class:: Schedule
|
.. class:: Schedule
|
||||||
|
|||||||
+46
-1
@@ -2,6 +2,8 @@ Tasks
|
|||||||
=====
|
=====
|
||||||
.. py:currentmodule:: django_q
|
.. py:currentmodule:: django_q
|
||||||
|
|
||||||
|
.. _async:
|
||||||
|
|
||||||
Async
|
Async
|
||||||
-----
|
-----
|
||||||
|
|
||||||
@@ -31,6 +33,48 @@ 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)
|
||||||
|
|
||||||
|
:func:`async` can take the following optional keyword arguments:
|
||||||
|
|
||||||
|
hook
|
||||||
|
""""
|
||||||
|
The function to call after the task has been executed. This function gets passed the complete :class:`Task` object as its argument.
|
||||||
|
|
||||||
|
group
|
||||||
|
"""""
|
||||||
|
A group label. Check :ref:`groups` for group functions
|
||||||
|
|
||||||
|
save
|
||||||
|
""""
|
||||||
|
Overrides the result backend's save setting.
|
||||||
|
|
||||||
|
timeout
|
||||||
|
"""""""
|
||||||
|
Overrides the cluster's timeout setting.
|
||||||
|
|
||||||
|
sync
|
||||||
|
""""
|
||||||
|
Simulates a task execution synchronously. Useful for testing.
|
||||||
|
|
||||||
|
redis
|
||||||
|
"""""
|
||||||
|
A redis connection. In case you want to control your own connections.
|
||||||
|
|
||||||
|
q_options
|
||||||
|
"""""""""
|
||||||
|
None of the option keywords get passed on to the function.
|
||||||
|
As an alternative you can also put them in
|
||||||
|
a single keyword dict named ``q_options``. This enables you to use these keywords for your function call::
|
||||||
|
|
||||||
|
# Async options in a dict
|
||||||
|
|
||||||
|
opts = {'hook': 'hooks.print_result',
|
||||||
|
'group': 'math',
|
||||||
|
'timeout': 30}
|
||||||
|
|
||||||
|
async('math.modf', 2.5, q_options=opts)
|
||||||
|
|
||||||
|
Please not that this will override any other option keywords.
|
||||||
|
|
||||||
.. _groups:
|
.. _groups:
|
||||||
|
|
||||||
Groups
|
Groups
|
||||||
@@ -133,7 +177,7 @@ Reference
|
|||||||
---------
|
---------
|
||||||
|
|
||||||
.. py:function:: async(func, *args, hook=None, group=None, timeout=None,\
|
.. py:function:: async(func, *args, hook=None, group=None, timeout=None,\
|
||||||
sync=False, redis=None, **kwargs)
|
sync=False, redis=None, q_options=None, **kwargs)
|
||||||
|
|
||||||
Puts a task in the cluster queue
|
Puts a task in the cluster queue
|
||||||
|
|
||||||
@@ -144,6 +188,7 @@ Reference
|
|||||||
: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 dict q_options: Options dict, overrides option keywords
|
||||||
:param dict 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
|
||||||
|
|||||||
Reference in New Issue
Block a user