diff --git a/docs/schedules.rst b/docs/schedules.rst index c726e0d..e5d36e6 100644 --- a/docs/schedules.rst +++ b/docs/schedules.rst @@ -25,6 +25,13 @@ You can manage them through the :ref:`admin_page` or directly from your code wit 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 ------------------- @@ -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 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 dict q_options: async options to use for this schedule :param kwargs: optional keyword arguments for the scheduled function. .. class:: Schedule diff --git a/docs/tasks.rst b/docs/tasks.rst index dd18214..d040a8e 100644 --- a/docs/tasks.rst +++ b/docs/tasks.rst @@ -2,6 +2,8 @@ Tasks ===== .. py:currentmodule:: django_q +.. _async: + Async ----- @@ -31,6 +33,48 @@ Use :func:`async` from your code to quickly offload tasks to the :class:`Cluster def print_result(task): 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 @@ -133,7 +177,7 @@ Reference --------- .. 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 @@ -144,6 +188,7 @@ Reference :param int timeout: Overrides global cluster :ref:`timeout`. :param bool sync: If set to True, async will simulate a task execution :param redis: Optional redis connection + :param dict q_options: Options dict, overrides option keywords :param dict kwargs: Keyword arguments for the task function :returns: The uuid of the task :rtype: str