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:
@@ -120,25 +120,14 @@ impl ProduceWorker {
|
|||||||
|
|
||||||
let finished_productions = match self.get_finished_productions() {
|
let finished_productions = match self.get_finished_productions() {
|
||||||
Ok(rows) => rows,
|
Ok(rows) => rows,
|
||||||
Err(err) => {
|
Err(_) => Vec::new(),
|
||||||
eprintln!("[ProduceWorker] Fehler in getFinishedProductions: {err}");
|
|
||||||
Vec::new()
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.base
|
self.base
|
||||||
.set_current_step("Process Finished Productions");
|
.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 {
|
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) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,32 +171,24 @@ impl ProduceWorker {
|
|||||||
let mut remaining_quantity = quantity;
|
let mut remaining_quantity = quantity;
|
||||||
let stocks = match self.get_available_stocks(branch_id) {
|
let stocks = match self.get_available_stocks(branch_id) {
|
||||||
Ok(rows) => rows,
|
Ok(rows) => rows,
|
||||||
Err(err) => {
|
Err(_) => Vec::new(),
|
||||||
eprintln!("[ProduceWorker] Fehler in getAvailableStocks: {err}");
|
|
||||||
Vec::new()
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Ruhemodus: keine Info-Logs, nur Fehler
|
|
||||||
|
|
||||||
for stock in stocks {
|
for stock in stocks {
|
||||||
if remaining_quantity <= 0 {
|
if remaining_quantity <= 0 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let free_capacity = stock.total_capacity - stock.filled;
|
let free_capacity = stock.total_capacity - stock.filled;
|
||||||
// keine Debug-Ausgabe
|
|
||||||
if free_capacity <= 0 {
|
if free_capacity <= 0 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let to_store = min(remaining_quantity, free_capacity);
|
let to_store = min(remaining_quantity, free_capacity);
|
||||||
// keine Debug-Ausgabe
|
|
||||||
if !self.store_in_stock(stock.stock_id, product_id, to_store, quality) {
|
if !self.store_in_stock(stock.stock_id, product_id, to_store, quality) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
remaining_quantity -= to_store;
|
remaining_quantity -= to_store;
|
||||||
// keine Debug-Ausgabe
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if remaining_quantity == 0 {
|
if remaining_quantity == 0 {
|
||||||
@@ -277,23 +258,17 @@ impl ProduceWorker {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Wenn kein Update stattfand, Insert versuchen
|
// Wenn kein Update stattfand, Insert versuchen
|
||||||
if let Err(err) = self.insert_inventory(stock_id, product_id, quantity, quality) {
|
if self.insert_inventory(stock_id, product_id, quantity, quality).is_err() {
|
||||||
eprintln!("[ProduceWorker] Fehler beim Insert in storeInStock: {err}");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(_) => false,
|
||||||
eprintln!("[ProduceWorker] Fehler beim Update in storeInStock: {err}");
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn delete_production(&self, production_id: i32) {
|
fn delete_production(&self, production_id: i32) {
|
||||||
if let Err(err) = self.remove_production(production_id) {
|
let _ = self.remove_production(production_id);
|
||||||
eprintln!("[ProduceWorker] Fehler beim Löschen der Produktion: {err}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_production_to_log(
|
fn add_production_to_log(
|
||||||
@@ -303,9 +278,7 @@ impl ProduceWorker {
|
|||||||
product_id: i32,
|
product_id: i32,
|
||||||
quantity: i32,
|
quantity: i32,
|
||||||
) {
|
) {
|
||||||
if let Err(err) = self.insert_or_update_production_log(region_id, user_id, product_id, quantity) {
|
let _ = self.insert_or_update_production_log(region_id, user_id, product_id, quantity);
|
||||||
eprintln!("[ProduceWorker] Fehler in addProductionToLog: {err}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_production_ready_event(
|
fn send_production_ready_event(
|
||||||
@@ -324,13 +297,7 @@ impl ProduceWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handle_overproduction(&self, user_id: i32, branch_id: i32, remaining_quantity: i32) {
|
fn handle_overproduction(&self, user_id: i32, branch_id: i32, remaining_quantity: i32) {
|
||||||
if let Err(err) =
|
let _ = self.insert_overproduction_notification(user_id, branch_id, remaining_quantity);
|
||||||
self.insert_overproduction_notification(user_id, branch_id, remaining_quantity)
|
|
||||||
{
|
|
||||||
eprintln!(
|
|
||||||
"[ProduceWorker] Fehler beim Schreiben der Overproduction-Notification: {err}"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let update_status =
|
let update_status =
|
||||||
format!(r#"{{"event":"falukantUpdateStatus","user_id":{user_id}}}"#);
|
format!(r#"{{"event":"falukantUpdateStatus","user_id":{user_id}}}"#);
|
||||||
@@ -480,13 +447,7 @@ impl ProduceWorker {
|
|||||||
&[&user_id, &branch_id, &remaining_quantity],
|
&[&user_id, &branch_id, &remaining_quantity],
|
||||||
) {
|
) {
|
||||||
Ok(_) => return Ok(()),
|
Ok(_) => return Ok(()),
|
||||||
Err(err) => {
|
Err(_) => { /* Fallback: Erstelle neue Benachrichtigung */ }
|
||||||
eprintln!(
|
|
||||||
"[ProduceWorker] Fehler beim Aktualisieren der Overproduction-Notification für User {} Branch {}: {}. Erstelle neue Benachrichtigung.",
|
|
||||||
user_id, branch_id, err
|
|
||||||
);
|
|
||||||
// Fallback: Erstelle neue Benachrichtigung
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user