Tasks¶
Tasks are background processes that can be used to asynchronously run code with a specified trigger.
How They Work¶
Tasks work by creating an asyncio.Task
to run a loop to check if the task is ready to be run based on the provided trigger. Using them is fairly easy, and the easiest way is via Decorators.
Decorators are by far the easier way to run tasks, with very simple syntax to get started.
1 2 3 4 5 |
|
You can also manually register tasks
1 2 3 4 5 6 |
|
By default, there are a few triggers available to the user.
These triggers run every set interval.
1 2 3 4 5 |
|
These triggers are similar to IntervalTriggers, but instead run when a specified datetime is reached.
1 2 3 4 5 6 7 8 |
|
These triggers are similar to DateTriggers, but trigger daily at the specified hour, minute, and second.
1 2 3 4 5 |
|
These triggers are special, in that you can pass in a list of different triggers, and if any of them are triggered, it runs the function.
1 2 3 4 5 |
|
Starting a task¶
To start a task that has been created, you need to run the Task.start()
method from an async
function. A good place to do this is during on_startup
:
1 2 3 4 5 6 7 8 9 10 11 |
|
1 2 3 4 5 6 7 8 9 10 11 |
|