Overview
The Malbox scheduler is a multi-tier asynchronous scheduling system that coordinates task queuing, worker pool allocation, resource provisioning, and plugin execution lifecycle. Think of the scheduler as the central event loop that orchestrates the entire task management system.Architecture
The scheduler implements an event-driven architecture built on Tokio’s asynchronous runtime. At its core is atokio::select! loop that multiplexes four distinct event streams:
- New task submission notifications
- Worker completion events
- Queued task signals
- Shutdown requests
Task Store
The task store provides persistent database storage combined with an in-memory cache for efficient retrieval of recent submissions.Task Queue
The task queue implements priority-based ordering using a binary heap. Task priority determines processing order when resources become available.The task queue stores only task IDs, actual task contents are retrieved from the task store.
Worker Pool
The worker pool manages the lifecycle of worker instances, tracking which workers are idle and available for new tasks. See Workers for more details.Communication
Components communicate exclusively through typed channels:- Task submissions - External systems submit tasks via an mpsc channel
- Worker events - Workers report status through a dedicated mpsc channel
- Shutdown coordination - A oneshot channel enables graceful termination of the scheduler event loop