Skip to content

Scheduling and Dispatch

Dmitri Chudinov edited this page Aug 28, 2026 · 1 revision

Scheduling and dispatch

The planner is the product. "The system finds a free appropriate printer" and "if there is no free printer, it waits" are two lines of the scenario and most of the engineering.

Like the pricing engine, plan() is a pure function with no I/O, so it can be tested against fixtures and replayed in the virtual farm:

def plan(jobs: list[ReadyJob], printers: list[PrinterState],
         now: datetime, policy: SchedulingPolicy) -> list[Assignment | WaitListEntry]: ...

1. Eligibility — the hard constraints

A machine is eligible for a job only if all of these hold. Each failure is recorded as a code, and the codes are grouped by what would clear them:

Rejection code Group Clears when
reject.build_volume structural never, on this machine
reject.nozzle structural never, on this machine
reject.no_multi_material structural never, on this machine
reject.busy transient the machine finishes
reject.in_maintenance transient service completes
reject.no_storage transient storage frees up
reject.material_not_loaded material somebody mounts filament
reject.insufficient_material material somebody mounts filament
reject.colour_not_loaded material somebody mounts filament

That grouping is not bookkeeping — it is what makes the wait list honest. See §4.

2. Job ordering

Due-date risk first, then explicit priority, then job id. The last term is there purely so that two runs of the planner cannot disagree about work already acted on: a tie under a LIMIT moves rows in and out of the batch, so unchanged data would read differently twice.

Rush is a real input here, not a label. A rushed order buys both a price uplift and a place further up this ordering.

3. Scoring — choosing among eligible machines

Every component is a penalty in [0, 1] scaled by a weight, and the cheapest machine wins. One direction throughout means a new term cannot accidentally invert the comparison.

Component Default weight What it discourages
capability waste 3 Spending a multi-material machine on a single-colour job
material headroom 4 Choosing a spool that only just covers the plate over one with room to spare
amortization 1 Preferring an expensive machine when a cheaper one will do
load balance 2 Piling work onto one machine

Every weight is injected (ADR-0010) and editable in the console's settings, so a farm that wants to protect due dates above utilisation can say so without a code change.

Two terms were removed in Phase 4, and the reason is instructive. The design originally listed changeover cost and batching affinity as the first two soft terms. Implementing it showed both are unreachable: eligibility already requires the material and every requested colour to be mounted, so every machine the scorer sees has them, and both terms are identically zero for every candidate. Weighting a constant cannot change an outcome. Changeover becomes a real cost again only once jobs can be planned onto machines that are still busy — queue depth, which is not built.

4. The wait list, and the reason it refuses to guess

No eligible machine means a WaitListEntry with a reason:

Reason Meaning predicted_start
waitlist.awaiting_capacity Every capable machine is busy with a known finish time set — time alone will fix this
waitlist.material_not_loaded The job needs filament nobody has mounted None
waitlist.no_capable_printer No machine on the farm can print this plate as configured None

predicted_start is set only when time alone will fix the wait. Nothing in the system knows when a person will walk over with a spool, and waiting will never help a job no machine can print — a human has to decide. Naming a start time in either case would be the queue's version of a driver inventing telemetry for an unreachable printer.

Wait-list entries are re-evaluated on every relevant event, not only on a timer: job.ready, printer.became_idle, material.mounted, order.priority_changed.

5. Every decision is recorded

Each planning pass writes an AssignmentDecision: the candidates considered, every reason each was refused (not just the first), and the winning score components.

That includes jobs that were not assigned. A schema that could only explain the winners could not answer "why was my job skipped", which is the question a customer actually asks. GET /jobs/{id}/decisions serves it.

6. Dispatch

Once assigned, the worker uploads the plate to the machine and starts it:

ready → assigned → dispatching → printing

dispatching covers the upload and the start command, and exists because an upload that dies halfway must not look like either state around it. A dispatch that fails returns the job to ready — nothing was printed and no material was spent, so another machine can simply be tried.

For a Bambu machine the transport is FTPS on :990 for the 3MF and MQTT over TLS on :8883 for the start command and the AMS mapping. See Fleet and Drivers.

7. Triggers

Trigger Source
Every scheduler_tick_seconds (default 30) workers/scheduler.py
job.ready a plate was attached
printer.became_free telemetry saw a machine finish
fleet state changes telemetry

The event wake-ups are what stop a machine that finishes one second after a tick from idling for the remaining twenty-nine.

8. Tuning it

Console → Settings → Scheduling. The weights above, the tick interval, and the policy knobs. Every value is a farm setting rather than a constant, and every save is audited with a «было · стало» record. See Configuration.

Related

Clone this wiki locally