diff --git a/src/worker/director.rs b/src/worker/director.rs index 5a420c4..1b5dfa6 100644 --- a/src/worker/director.rs +++ b/src/worker/director.rs @@ -372,14 +372,37 @@ impl DirectorWorker { conn.prepare("get_to_produce", QUERY_GET_BEST_PRODUCTION)?; let rows = conn.execute("get_to_produce", &[&director.id])?; if rows.is_empty() { + eprintln!( + "[DirectorWorker] Keine Produktionskandidaten für Director {} gefunden.", + director.id + ); return Ok(()); } let plan = match Self::map_row_to_production_plan(&rows[0]) { Some(p) => p, - None => return Ok(()), + None => { + eprintln!( + "[DirectorWorker] Produktionsplan für Director {} konnte nicht gemappt werden.", + director.id + ); + return Ok(()); + } }; + eprintln!( + "[DirectorWorker] Produktionsplan: director_user_id={}, branch_id={}, product_id={}, money={}, certificate={}, stock_size={}, used_in_stock={}, running_productions={}, running_qty={}", + plan.falukant_user_id, + plan.branch_id, + plan.product_id, + plan.money, + plan.certificate, + plan.stock_size, + plan.used_in_stock, + plan.running_productions, + plan.running_productions_quantity + ); + self.create_production_batches(&mut conn, &plan)?; Ok(()) } @@ -410,6 +433,10 @@ impl DirectorWorker { ) -> Result<(), DbError> { let running = plan.running_productions; if running >= 2 { + eprintln!( + "[DirectorWorker] Bereits zu viele laufende Produktionen ({}), keine neue Produktion.", + running + ); return Ok(()); } @@ -430,6 +457,14 @@ impl DirectorWorker { let to_produce = free_capacity.min(max_money_production).min(300).max(0); + eprintln!( + "[DirectorWorker] Produktionsberechnung: free_capacity={}, one_piece_cost={}, max_money_production={}, to_produce={}", + free_capacity, + one_piece_cost, + max_money_production, + to_produce + ); + if to_produce < 1 { eprintln!( "[DirectorWorker] Keine Produktion gestartet: free_capacity={}, max_money_production={}, running_productions={}, running_qty={}", @@ -456,6 +491,7 @@ impl DirectorWorker { conn.prepare("insert_production", QUERY_INSERT_PRODUCTION)?; let mut remaining = to_produce; + let mut inserted_total = 0; while remaining > 0 { let batch = remaining.min(100); conn.execute( @@ -463,8 +499,14 @@ impl DirectorWorker { &[&plan.branch_id, &plan.product_id, &batch], )?; remaining -= batch; + inserted_total += batch; } + eprintln!( + "[DirectorWorker] Produktion angelegt: branch_id={}, product_id={}, quantity={}", + plan.branch_id, plan.product_id, inserted_total + ); + let message = format!( r#"{{"event":"production_started","branch_id":{}}}"#, plan.branch_id