Refactor error handling in ProduceWorker: Simplify error logging by removing detailed error messages and replacing them with silent error handling. This change streamlines the code and reduces console output during production processing, while maintaining functionality.

This commit is contained in:
Torsten Schulz (local)
2026-02-02 15:18:44 +01:00
parent 2f875d6c1c
commit 460310ae89

View File

@@ -120,25 +120,14 @@ impl ProduceWorker {
let finished_productions = match self.get_finished_productions() {
Ok(rows) => rows,
Err(err) => {
eprintln!("[ProduceWorker] Fehler in getFinishedProductions: {err}");
Vec::new()
}
Err(_) => Vec::new(),
};
self.base
.set_current_step("Process Finished Productions");
eprintln!("[ProduceWorker] {} fertige Produktionen gefunden", finished_productions.len());
// Verarbeite Produktionen einzeln und prüfe nach jeder, ob noch Platz ist
for production in finished_productions {
// Prüfe nochmal, ob genug Lagerplatz vorhanden ist, bevor wir verarbeiten
if !self.has_enough_capacity(production.branch_id, production.quantity) {
eprintln!(
"[ProduceWorker] Überspringe Produktion {} (branch_id={}, quantity={}): Kein ausreichender Lagerplatz",
production.production_id, production.branch_id, production.quantity
);
continue;
}
@@ -182,32 +171,24 @@ impl ProduceWorker {
let mut remaining_quantity = quantity;
let stocks = match self.get_available_stocks(branch_id) {
Ok(rows) => rows,
Err(err) => {
eprintln!("[ProduceWorker] Fehler in getAvailableStocks: {err}");
Vec::new()
}
Err(_) => Vec::new(),
};
// Ruhemodus: keine Info-Logs, nur Fehler
for stock in stocks {
if remaining_quantity <= 0 {
break;
}
let free_capacity = stock.total_capacity - stock.filled;
// keine Debug-Ausgabe
if free_capacity <= 0 {
continue;
}
let to_store = min(remaining_quantity, free_capacity);
// keine Debug-Ausgabe
if !self.store_in_stock(stock.stock_id, product_id, to_store, quality) {
return false;
}
remaining_quantity -= to_store;
// keine Debug-Ausgabe
}
if remaining_quantity == 0 {
@@ -277,23 +258,17 @@ impl ProduceWorker {
return true;
}
// Wenn kein Update stattfand, Insert versuchen
if let Err(err) = self.insert_inventory(stock_id, product_id, quantity, quality) {
eprintln!("[ProduceWorker] Fehler beim Insert in storeInStock: {err}");
if self.insert_inventory(stock_id, product_id, quantity, quality).is_err() {
return false;
}
true
}
Err(err) => {
eprintln!("[ProduceWorker] Fehler beim Update in storeInStock: {err}");
false
}
Err(_) => false,
}
}
fn delete_production(&self, production_id: i32) {
if let Err(err) = self.remove_production(production_id) {
eprintln!("[ProduceWorker] Fehler beim Löschen der Produktion: {err}");
}
let _ = self.remove_production(production_id);
}
fn add_production_to_log(
@@ -303,9 +278,7 @@ impl ProduceWorker {
product_id: i32,
quantity: i32,
) {
if let Err(err) = self.insert_or_update_production_log(region_id, user_id, product_id, quantity) {
eprintln!("[ProduceWorker] Fehler in addProductionToLog: {err}");
}
let _ = self.insert_or_update_production_log(region_id, user_id, product_id, quantity);
}
fn send_production_ready_event(
@@ -324,13 +297,7 @@ impl ProduceWorker {
}
fn handle_overproduction(&self, user_id: i32, branch_id: i32, remaining_quantity: i32) {
if let Err(err) =
self.insert_overproduction_notification(user_id, branch_id, remaining_quantity)
{
eprintln!(
"[ProduceWorker] Fehler beim Schreiben der Overproduction-Notification: {err}"
);
}
let _ = self.insert_overproduction_notification(user_id, branch_id, remaining_quantity);
let update_status =
format!(r#"{{"event":"falukantUpdateStatus","user_id":{user_id}}}"#);
@@ -480,13 +447,7 @@ impl ProduceWorker {
&[&user_id, &branch_id, &remaining_quantity],
) {
Ok(_) => return Ok(()),
Err(err) => {
eprintln!(
"[ProduceWorker] Fehler beim Aktualisieren der Overproduction-Notification für User {} Branch {}: {}. Erstelle neue Benachrichtigung.",
user_id, branch_id, err
);
// Fallback: Erstelle neue Benachrichtigung
}
Err(_) => { /* Fallback: Erstelle neue Benachrichtigung */ }
}
}