Task Manager¶
It can be imported from fluid.scheduler
:
fluid.scheduler.TaskManager
¶
The task manager is the main class for managing tasks
Source code in fluid/scheduler/consumer.py
deps
instance-attribute
¶
Dependencies for the task manager.
Production applications requires global dependencies to be
available to all tasks. This can be achieved by setting
the deps
attribute of the task manager to an object
with the required dependencies.
Each task can cast the dependencies to the required type.
config
instance-attribute
¶
config = config or TaskManagerConfig(**kwargs)
Task manager configuration
dispatcher
instance-attribute
¶
dispatcher = TaskDispatcher()
A dispatcher of TaskRun events.
Application can register handlers to listen for events happening during the lifecycle of a task run.
enter_async_context
async
¶
execute
async
¶
Execute a task and wait for it to finish
on_shutdown
async
¶
execute_sync
¶
register_task
¶
Register a task with the task manager
Only tasks registered can be executed by a task manager
queue
async
¶
Queue a task for execution
This methods fires two events:
- init: when the task run is created
- queued: after the task is queued
Source code in fluid/scheduler/consumer.py
create_task_run
¶
Create a TaskRun in init
state
Source code in fluid/scheduler/consumer.py
register_from_module
¶
register_from_dict
¶
register_async_handler
¶
Register an async handler for a given event
This method is a no op for a TaskManager that is not a worker
unregister_async_handler
¶
Unregister an async handler for a given event
This method is a no op for a TaskManager that is not a worker
fluid.scheduler.TaskManagerConfig
pydantic-model
¶
Bases: BaseModel
Task manager configuration
Fields:
-
schedule_tasks
(bool
) -
consume_tasks
(bool
) -
max_concurrent_tasks
(int
) -
sleep
(float
) -
broker_url
(str
)
max_concurrent_tasks
pydantic-field
¶
The number of coroutine workers consuming tasks. Each worker consumes one task at a time, therefore, this number is the maximum number of tasks that can run concurrently.It can be configured via the FLUID_MAX_CONCURRENT_TASKS
environment variable, and by default is set to 5.