Task Manager Plugins¶
Plugins extend the TaskManager with additional behaviour by hooking into task lifecycle events.
A plugin implements the TaskManagerPlugin interface and is registered via TaskManager.with_plugin.
from fluid.scheduler import TaskScheduler, task_manager_fastapi
from fluid.scheduler.db import TaskDbPlugin
task_manager = TaskScheduler(...)
task_manager.with_plugin(TaskDbPlugin(db))
app = task_manager_fastapi(task_manager)
fluid.scheduler.TaskManagerPlugin
¶
Bases: ABC
Plugin for a task Manager
register
abstractmethod
¶
register_routes
¶
Register routes with the FastAPI app
| PARAMETER | DESCRIPTION |
|---|---|
app
|
FastAPI app instance.
TYPE:
|
prefix
|
The URL prefix for the routes.
TYPE:
|
tags
|
The tags for the routes.
TYPE:
|
Source code in fluid/scheduler/plugin.py
fluid.scheduler.db.TaskDbPlugin
¶
Bases: TaskManagerPlugin
A plugin to store TaskRun in a postgresql database.
This plugin listens to task state changes and updates the database accordingly. It requires a CrudDB instance to perform database operations and allows customization of the table name and event tags.
You can use the skip_db tag to prevent database operations for specific tasks.
It can be used if the db extra is installed, and requires a compatible
database backend supported by CrudDB.
| PARAMETER | DESCRIPTION |
|---|---|
table_name
|
The name of the table to store task runs
TYPE:
|
tag
|
The tag for the plugin event registration
TYPE:
|
skip_db_tag
|
The tag to skip database operations
TYPE:
|
route_prefix
|
Fix the URL prefix for the history routes. If None, routes are registered using the prefix parameter from register_routes.
TYPE:
|
Source code in fluid/scheduler/db.py
register
¶
Source code in fluid/scheduler/db.py
register_routes
¶
Register routes with the FastAPI app
| PARAMETER | DESCRIPTION |
|---|---|
app
|
FastAPI app instance.
TYPE:
|
prefix
|
The URL prefix for the routes.
TYPE:
|
tags
|
The tags for the routes.
TYPE:
|
Source code in fluid/scheduler/db.py
get_history
async
¶
Get task run history based on the provided query parameters.
| PARAMETER | DESCRIPTION |
|---|---|
q
|
Query parameters for fetching task run history
TYPE:
|
Source code in fluid/scheduler/db.py
get_run
async
¶
Get a specific task run by its ID.
Source code in fluid/scheduler/db.py
Accessing the plugin from a task¶
get_db_plugin retrieves the registered
TaskDbPlugin from the task manager state.
It is designed as a FastAPI dependency for route handlers, but can also be
called directly from within a task by passing context.task_manager:
from fluid.scheduler import TaskRun, task
from fluid.scheduler.db import get_db_plugin, TaskHistoryQuery
@task()
async def report(context: TaskRun) -> None:
db_plugin = get_db_plugin(context.task_manager)
page = await db_plugin.get_history(TaskHistoryQuery(task="my-task", limit=10))
for run in page.data:
print(run.id, run.state)
fluid.scheduler.db.get_db_plugin
¶
Retrieve the registered TaskDbPlugin.
Can be used as a FastAPI dependency in route handlers, or called directly
from within a task by passing context.task_manager.
Source code in fluid/scheduler/db.py
History Models¶
The following models are used when querying task run history via TaskDbPlugin.get_history or the HTTP endpoints.
They can be imported from fluid.scheduler.db:
Filtering by tags¶
The tags field of TaskHistoryQuery
filters runs by the tags of their Task. A run matches
when its task carries at least one of the supplied tags (OR semantics, the
same as the tags query parameter on the task list endpoint). Tags are
resolved against the live task registry at query time, so they always reflect
each task's current tags rather than the tags it had when the run executed.
When combined with the task filter, the two are applied together (AND): the
run's task must match the name and carry one of the tags. Tags that match no
registered task return an empty result.
fluid.scheduler.db.TaskHistoryQuery
pydantic-model
¶
Bases: BaseModel
Query parameters for fetching task run history.
Fields:
-
task(str | None) -
start(datetime | None) -
end(datetime | None) -
state(TaskState | None) -
params(dict[str, Any] | str | None) -
tags(list[str] | None) -
limit(int | None) -
cursor(str)
Validators:
-
_parse_params_str
tags
pydantic-field
¶
Filter runs whose task has at least one of these tags when provided. Tags are resolved against the live task registry, so they reflect each task's current tags.
fluid.scheduler.db.TaskRunHistory
pydantic-model
¶
fluid.scheduler.db.TaskRunHistoryPage
pydantic-model
¶
Bases: BaseModel
A paginated response containing a list of task run history records.
Returned by TaskDbPlugin.get_history
and the GET /task-history endpoint.
Fields:
-
data(list[TaskRunHistory]) -
cursor(str)