Implement periodic ping frames in WebSocket server for keepalive and update overproduction handling in ProduceWorker to include branch_id. This enhances connection stability and improves notification clarity for overproduction events.

This commit is contained in:
Torsten Schulz (local)
2025-12-01 13:25:23 +01:00
parent 3e9f921f4f
commit b8fa644c97
2 changed files with 28 additions and 6 deletions

View File

@@ -271,7 +271,9 @@ impl ProduceWorker {
self.send_production_ready_event(user_id, product_id, quantity, quality, branch_id);
true
} else {
self.handle_overproduction(user_id, remaining_quantity);
// Es konnten nicht alle produzierten Einheiten eingelagert werden
// Überproduktion für diesen Branch melden.
self.handle_overproduction(user_id, branch_id, remaining_quantity);
true
}
}
@@ -331,8 +333,10 @@ impl ProduceWorker {
self.base.broker.publish(message);
}
fn handle_overproduction(&self, user_id: i32, remaining_quantity: i32) {
if let Err(err) = self.insert_overproduction_notification(user_id, remaining_quantity) {
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}"
);
@@ -424,6 +428,7 @@ impl ProduceWorker {
fn insert_overproduction_notification(
&self,
user_id: i32,
branch_id: i32,
remaining_quantity: i32,
) -> Result<(), crate::db::DbError> {
let mut conn = self
@@ -437,9 +442,11 @@ impl ProduceWorker {
QUERY_ADD_OVERPRODUCTION_NOTIFICATION,
)?;
// Zusätzlich zur Menge die Branch-ID in der Payload mitschicken, damit
// das Frontend die Überproduktion einem konkreten Branch zuordnen kann.
let notification = format!(
r#"{{"tr":"production.overproduction","value":{}}}"#,
remaining_quantity
r#"{{"tr":"production.overproduction","value":{},"branch_id":{}}}"#,
remaining_quantity, branch_id
);
conn.execute(