Implement capacity check in ProduceWorker: Add a method to verify available storage before processing finished productions, ensuring that production only occurs if sufficient capacity is present. Update SQL query to reflect the new capacity validation logic for improved reliability in production handling.
This commit is contained in:
@@ -1435,10 +1435,12 @@ pub const QUERY_GET_FINISHED_PRODUCTIONS: &str = r#"
|
||||
-- Wetter-Effekte derzeit aus der Qualitätsberechnung entfernt
|
||||
WHERE p.start_timestamp + INTERVAL '1 minute' * pr.production_time <= NOW()
|
||||
-- Nur Produktionen zurückgeben, für die genug Lagerplatz vorhanden ist
|
||||
-- running_productions_quantity enthält bereits p.quantity, daher prüfen wir:
|
||||
-- (stock_size - used_in_stock - running_productions_quantity) >= 0
|
||||
-- Das bedeutet: Nach Abzug aller laufenden Produktionen muss noch Platz vorhanden sein
|
||||
AND (capacity.stock_size - capacity.used_in_stock - capacity.running_productions_quantity) >= 0
|
||||
-- running_productions_quantity enthält bereits p.quantity
|
||||
-- Nach dem Abschluss von p muss Platz sein: stock_size - used_in_stock - (running_productions_quantity - p.quantity) >= p.quantity
|
||||
-- Vereinfacht: stock_size - used_in_stock - running_productions_quantity + p.quantity >= p.quantity
|
||||
-- Oder: stock_size - used_in_stock - running_productions_quantity >= 0
|
||||
-- ABER: Wir müssen sicherstellen, dass p.quantity auch wirklich Platz hat
|
||||
AND (capacity.stock_size - capacity.used_in_stock - capacity.running_productions_quantity + p.quantity) >= p.quantity
|
||||
ORDER BY p.start_timestamp;
|
||||
"#;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user