External API
External API of the aioclock package, that can be used to interact with the AioClock instance. This module could be very useful if you intend to use aioclock in a web application or a CLI tool.
Other tools and extension are written from this tool.
Note when writing to aioclock API and changing its state.
Right now the state of AioClock instance is on the memory level, so if you write an API and change a task's trigger time, it will not persist. In future we might store the state of AioClock instance in a database, so that it always remains same. But this is a bit tricky and implicit because then your code gets ignored and database is preferred over the codebase. For now you may consider it as a way to change something without redeploying the application, but it is not very recommended to write.
TaskMetadata ¶
Bases: BaseModel
Metadata of the task that is included in the AioClock instance.
Attributes:
Name | Type | Description |
---|---|---|
id |
UUID
|
UUID: Task ID that is unique for each task, and changes every time you run the aioclock app. In future we might store task ID in a database, so that it always remains same. |
trigger |
Union[TriggerT, Any]
|
Union[TriggerT, Any]: Trigger that is used to run the task, type is also any to ease implementing new triggers. |
task_name |
str
|
str: Name of the task function. |
run_specific_task
async
¶
run_specific_task(task_id: UUID, app: AioClock)
Run a specific task immediately by its ID, from the AioClock instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_id |
UUID
|
Task ID that is unique for each task, and changes every time you run the aioclock app. In future we might store task ID in a database, so that it always remains same. |
required |
app |
AioClock
|
AioClock instance to run the task from. |
required |
Example
Source code in aioclock/api.py
run_with_injected_deps
async
¶
Runs an aioclock decorated function, with all the dependencies injected.
Can be used to run a task function with all the dependencies injected.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
Callable[P, Awaitable[T]]
|
Function to run with all the dependencies injected. Must be decorated with |
required |
Example
from aioclock import Once, AioClock, Depends
from aioclock.api import run_with_injected_deps
app = AioClock()
def some_dependency():
return 1
@app.task(trigger=Once())
async def main(bar: int = Depends(some_dependency)):
print("Hello World")
return bar
async def some_other_func():
foo = await run_with_injected_deps(main)
assert foo == 1
Source code in aioclock/api.py
get_metadata_of_all_tasks
async
¶
get_metadata_of_all_tasks(
app: AioClock,
) -> list[TaskMetadata]
Get metadata of all tasks that are included in the AioClock instance.
This function can be used to mutate the TaskMetadata
object, i.e to change the trigger of a task.
But for now it is yet not recommended to do this, as you might experience some unexpected behavior.
But in next versions, I'd like to make it more stable and reliable on mutating the data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
app |
AioClock
|
AioClock instance to get the metadata of all tasks. |
required |