feat: implement notification system and backoff strategy for rTorrent polling

This commit is contained in:
spinline
2026-02-05 18:31:42 +03:00
parent 97086bf33a
commit e2a8e17eae
7 changed files with 158 additions and 11 deletions

View File

@@ -85,10 +85,24 @@ pub async fn add_torrent_handler(
tracing::error!("rTorrent returned fault: {}", response);
return StatusCode::INTERNAL_SERVER_ERROR;
}
let _ =
state
.event_bus
.send(shared::AppEvent::Notification(shared::SystemNotification {
level: shared::NotificationLevel::Success,
message: "Torrent added successfully".to_string(),
}));
StatusCode::OK
}
Err(e) => {
tracing::error!("Failed to add torrent: {}", e);
let _ =
state
.event_bus
.send(shared::AppEvent::Notification(shared::SystemNotification {
level: shared::NotificationLevel::Error,
message: format!("Failed to add torrent: {}", e),
}));
StatusCode::INTERNAL_SERVER_ERROR
}
}
@@ -121,7 +135,15 @@ pub async fn handle_torrent_action(
// Special handling for delete_with_data
if payload.action == "delete_with_data" {
return match delete_torrent_with_data(&client, &payload.hash).await {
Ok(msg) => (StatusCode::OK, msg).into_response(),
Ok(msg) => {
let _ = state.event_bus.send(shared::AppEvent::Notification(
shared::SystemNotification {
level: shared::NotificationLevel::Success,
message: format!("Torrent deleted with data: {}", payload.hash),
},
));
(StatusCode::OK, msg).into_response()
}
Err((status, msg)) => (status, msg).into_response(),
};
}
@@ -136,7 +158,16 @@ pub async fn handle_torrent_action(
let params = vec![RpcParam::from(payload.hash.as_str())];
match client.call(method, &params).await {
Ok(_) => (StatusCode::OK, "Action executed").into_response(),
Ok(_) => {
let _ =
state
.event_bus
.send(shared::AppEvent::Notification(shared::SystemNotification {
level: shared::NotificationLevel::Info,
message: format!("Action '{}' executed on torrent", payload.action),
}));
(StatusCode::OK, "Action executed").into_response()
}
Err(e) => {
tracing::error!("RPC error: {}", e);
(