Task Consumer¶
The task consumer is a TaskManager which is also a Workers that consumes tasks from the task queue and executes them. It can be imported from fluid.scheduler
:
fluid.scheduler.TaskConsumer
¶
Bases: TaskManager
, Workers
The Task Consumer is a Task Manager responsible for consuming tasks from a task queue
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.
num_concurrent_tasks
property
¶
The number of concurrent_tasks running in the consumer
status
async
¶
gracefully_stop
¶
is_running
¶
is_stopping
¶
run
async
¶
run the workers
Source code in fluid/utils/worker.py
start_running
¶
Source code in fluid/utils/worker.py
add_workers
¶
wait_for_exit
async
¶
create_task
¶
on_shutdown
async
¶
shutdown
async
¶
shutdown the workers
Source code in fluid/utils/worker.py
bail_out
¶
safe_run
async
¶
Context manager to run a worker safely
Source code in fluid/utils/worker.py
remove_workers
¶
remove workers from the workers
startup
async
¶
start the workers
Source code in fluid/utils/worker.py
register_callback
¶
Register a callback
The callback can be periodic or not.
Source code in fluid/utils/worker.py
enter_async_context
async
¶
execute
async
¶
Execute a task and wait for it to finish
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
¶
sync_queue
¶
sync_priority_queue
¶
num_concurrent_tasks_for
¶
queue_and_wait
async
¶
Queue a task and wait for it to finish