|
| 1 | +--- |
| 2 | +order: 4 |
| 3 | +--- |
| 4 | + |
| 5 | + |
| 6 | +# Available schedule sources |
| 7 | + |
| 8 | +These objects are used to fetch current schedule for tasks. |
| 9 | +Currently we have only one schedule source. |
| 10 | + |
| 11 | + |
| 12 | +## LabelScheduleSource |
| 13 | + |
| 14 | +This source parses labels of tasks, and if it finds a `schedule` label, it considers this task as scheduled. |
| 15 | + |
| 16 | +The format of the schedule label is the following: |
| 17 | + |
| 18 | +```python |
| 19 | +@broker.task( |
| 20 | + schedule=[ |
| 21 | + { |
| 22 | + "cron": "* * * * *", # type: str, required argument. |
| 23 | + "args": [], # type List[Any] | None, can be omitted. |
| 24 | + "kwargs": {}, # type: Dict[str, Any] | None, can be omitted. |
| 25 | + "labels": {}, # type: Dict[str, Any] | None, can be omitted. |
| 26 | + } |
| 27 | + ] |
| 28 | +) |
| 29 | +async def my_task(): |
| 30 | + ... |
| 31 | +``` |
| 32 | + |
| 33 | +Parameters: |
| 34 | +* `cron` - crontab string when to run the task. |
| 35 | +* `args` - args to use, when invoking the task. |
| 36 | +* `kwargs` - key-word arguments to use when invoking the task. |
| 37 | +* `labels` - additional labels to use wehn invoking the task. |
| 38 | + |
| 39 | +Usage: |
| 40 | + |
| 41 | +```python |
| 42 | +from taskiq.scheduler import TaskiqScheduler |
| 43 | +from taskiq.schedule_sources import LabelScheduleSource |
| 44 | + |
| 45 | +broker = ... |
| 46 | + |
| 47 | +scheduler = TaskiqScheduler( |
| 48 | + broker=broker, |
| 49 | + sources=[LabelScheduleSource(broker)], |
| 50 | +) |
| 51 | +``` |
| 52 | + |
| 53 | + |
| 54 | +::: warning Cool notice! |
| 55 | + |
| 56 | +In order to resolve all labels correctly, don't forget to import |
| 57 | +all task modules using CLI interface. |
| 58 | + |
| 59 | +::: |
0 commit comments