Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions scylla-server/src/controllers/rule_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use axum_extra::{
headers::{authorization::Basic, Authorization},
TypedHeader,
};
use tokio::sync::RwLock;
use tracing::debug;

use crate::{
Expand All @@ -16,7 +15,7 @@ use crate::{
#[debug_handler]
pub async fn add_rule(
TypedHeader(auth): TypedHeader<Authorization<Basic>>,
Extension(rules_manager): Extension<Arc<RwLock<RuleManager>>>,
Extension(rules_manager): Extension<Arc<RuleManager>>,
Json(rule): Json<Rule>,
) -> Result<Json<String>, ScyllaError> {
debug!(
Expand All @@ -25,9 +24,8 @@ pub async fn add_rule(
auth.username().to_string()
);
match rules_manager
.write()
.await
.add_rule(ClientId(auth.username().to_string()), rule)
.await
{
Ok(_) => Ok(Json::from("Rule added!".to_owned())),
Err(err) => Err(ScyllaError::RuleError(err)),
Expand All @@ -37,7 +35,7 @@ pub async fn add_rule(
#[debug_handler]
pub async fn delete_rule(
TypedHeader(auth): TypedHeader<Authorization<Basic>>,
Extension(rules_manager): Extension<Arc<RwLock<RuleManager>>>,
Extension(rules_manager): Extension<Arc<RuleManager>>,
Path(rule_id): Path<String>,
) -> Result<(), ScyllaError> {
debug!(
Expand All @@ -46,9 +44,8 @@ pub async fn delete_rule(
auth.username().to_string()
);
match rules_manager
.write()
.await
.delete_rule(ClientId(auth.username().to_string()), RuleId(rule_id))
.await
{
Ok(_) => Ok(()),
Err(err) => Err(ScyllaError::RuleError(err)),
Expand Down
4 changes: 2 additions & 2 deletions scylla-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use scylla_server::{
use socketioxide::{extract::SocketRef, SocketIo};
use tokio::{
signal,
sync::{broadcast, mpsc, RwLock},
sync::{broadcast, mpsc},
};
use tokio_util::{sync::CancellationToken, task::TaskTracker};
use tower::ServiceBuilder;
Expand Down Expand Up @@ -249,7 +249,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (db_send, db_receive) = mpsc::channel::<Vec<ClientData>>(1000);

// the rules manager
let rules_manager = Arc::new(RwLock::new(RuleManager::new()));
let rules_manager = Arc::new(RuleManager::new());

// the below two threads need to cancel cleanly to ensure all queued messages are sent. therefore they are part of the a task tracker group.
// create a task tracker and cancellation token
Expand Down
Loading