mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-07 10:18:11 +08:00
Schedule name is optional
For backwards compatibility the schedule name is an optional keyword in the `schedule` function. Adjusted docs accordingly
This commit is contained in:
+4
-1
@@ -54,6 +54,7 @@ def schedule(func, *args, **kwargs):
|
|||||||
"""
|
"""
|
||||||
:param func: function to schedule
|
:param func: function to schedule
|
||||||
:param args: function arguments
|
:param args: function arguments
|
||||||
|
:param name: optional name for the schedule
|
||||||
:param hook: optional result hook function
|
:param hook: optional result hook function
|
||||||
:type schedule_type: Schedule.TYPE
|
:type schedule_type: Schedule.TYPE
|
||||||
:param repeats: how many times to repeat. 0=never, -1=always
|
:param repeats: how many times to repeat. 0=never, -1=always
|
||||||
@@ -64,12 +65,14 @@ def schedule(func, *args, **kwargs):
|
|||||||
:rtype: Schedule
|
:rtype: Schedule
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
name = kwargs.pop('name', None)
|
||||||
hook = kwargs.pop('hook', None)
|
hook = kwargs.pop('hook', None)
|
||||||
schedule_type = kwargs.pop('schedule_type', Schedule.ONCE)
|
schedule_type = kwargs.pop('schedule_type', Schedule.ONCE)
|
||||||
repeats = kwargs.pop('repeats', -1)
|
repeats = kwargs.pop('repeats', -1)
|
||||||
next_run = kwargs.pop('next_run', timezone.now())
|
next_run = kwargs.pop('next_run', timezone.now())
|
||||||
|
|
||||||
return Schedule.objects.create(func=func,
|
return Schedule.objects.create(name=name,
|
||||||
|
func=func,
|
||||||
hook=hook,
|
hook=hook,
|
||||||
args=args,
|
args=args,
|
||||||
kwargs=kwargs,
|
kwargs=kwargs,
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ def test_scheduler(r):
|
|||||||
r.delete(list_key)
|
r.delete(list_key)
|
||||||
schedule = create_schedule('math.copysign',
|
schedule = create_schedule('math.copysign',
|
||||||
1, -1,
|
1, -1,
|
||||||
|
name='test math',
|
||||||
hook='django_q.tests.tasks.result',
|
hook='django_q.tests.tasks.result',
|
||||||
schedule_type=Schedule.HOURLY,
|
schedule_type=Schedule.HOURLY,
|
||||||
repeats=1)
|
repeats=1)
|
||||||
|
|||||||
+2
-1
@@ -11,7 +11,8 @@ Successful tasks
|
|||||||
----------------
|
----------------
|
||||||
|
|
||||||
Shows all successfully executed tasks. Meaning they did not encounter any errors during execution.
|
Shows all successfully executed tasks. Meaning they did not encounter any errors during execution.
|
||||||
From here you can look at details of each task or delete them.
|
From here you can look at details of each task or delete them. Use the group column to sort your results by schedule name or group id.
|
||||||
|
The table is searchable by `name`, `func` and `group`
|
||||||
|
|
||||||
Uses the :class:`Success` proxy model.
|
Uses the :class:`Success` proxy model.
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -48,12 +48,13 @@ If you want to schedule regular Django management commands, you can use the :mod
|
|||||||
Reference
|
Reference
|
||||||
---------
|
---------
|
||||||
|
|
||||||
.. py:function:: schedule(func, *args, hook=None, schedule_type='O', repeats=-1, next_run=now() , **kwargs)
|
.. py:function:: schedule(func, *args, name=None, 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 name: An optional name for your schedule.
|
||||||
:param str hook: optional result hook function. Dotted strings only.
|
:param str hook: optional result hook function. Dotted strings only.
|
||||||
: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.
|
||||||
@@ -70,7 +71,7 @@ Reference
|
|||||||
|
|
||||||
.. py:attribute:: name
|
.. py:attribute:: name
|
||||||
|
|
||||||
A name for your schedule. Tasks created by this schedule will assume this as their group id.
|
A name for your schedule. Tasks created by this schedule will assume this or the primary key as their group id.
|
||||||
|
|
||||||
.. py:attribute:: func
|
.. py:attribute:: func
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -54,7 +54,7 @@ Take care that you haven't limited your results database too much and that the g
|
|||||||
Instead of :func:`result_group` you can also use :func:`fetch_group` to return a list of :class:`Task` objects.
|
Instead of :func:`result_group` you can also use :func:`fetch_group` to return a list of :class:`Task` objects.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
Tasks created by a schedule, will use the schedules name as their group id.
|
Tasks created by a schedule, will use the schedule name as their group id. This enables you to browse the schedule's history.
|
||||||
|
|
||||||
Synchronous testing
|
Synchronous testing
|
||||||
-------------------
|
-------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user