Enhance production job handling in DirectorWorker: Implemented a limit on the number of concurrent production jobs per branch to a maximum of two. Updated SQL query for fetching finished productions to aggregate quality ratings correctly and ensure unique results per production ID. Improved comments for clarity on the logic and SQL structure.

This commit is contained in:
Torsten Schulz (local)
2025-12-01 14:32:31 +01:00
parent 02bd0de75d
commit bd9fbb80c0
2 changed files with 50 additions and 20 deletions

View File

@@ -460,6 +460,7 @@ impl DirectorWorker {
plan: &ProductionPlan,
) -> Result<(), DbError> {
let running = plan.running_productions;
// Maximal zwei parallele Produktionen pro Branch zulassen.
if running >= 2 {
eprintln!(
"[DirectorWorker] Bereits zu viele laufende Produktionen ({}), keine neue Produktion.",
@@ -530,16 +531,23 @@ impl DirectorWorker {
conn.prepare("insert_production", QUERY_INSERT_PRODUCTION)?;
let mut remaining = to_produce;
// Anzahl neuer Produktions-Jobs so begrenzen, dass zusammen mit den
// bereits laufenden maximal 2 parallele Produktionen pro Branch aktiv
// sind. Jeder Job wird in Batches von max. 100 Stück aufgeteilt.
let mut remaining_qty = to_produce;
let mut inserted_total = 0;
while remaining > 0 {
let batch = remaining.min(100);
let mut started_jobs = 0;
let max_new_jobs = (2 - running).max(0);
while remaining_qty > 0 && started_jobs < max_new_jobs {
let batch = remaining_qty.min(100);
conn.execute(
"insert_production",
&[&plan.branch_id, &plan.product_id, &batch],
)?;
remaining -= batch;
remaining_qty -= batch;
inserted_total += batch;
started_jobs += 1;
}
eprintln!(