Add API for propagating cursor locations #61
4 changed files with 5 additions and 26 deletions
Fix PR diff
commit
b25bc40851
|
|
@ -2,7 +2,6 @@ database:
|
||||||
databases_directory_path: databases
|
databases_directory_path: databases
|
||||||
max_connections_per_vault: 12
|
max_connections_per_vault: 12
|
||||||
cursor_timeout_seconds: 60
|
cursor_timeout_seconds: 60
|
||||||
cursor_broadcast_interval_seconds: 1
|
|
||||||
server:
|
server:
|
||||||
host: 0.0.0.0
|
host: 0.0.0.0
|
||||||
port: 3000
|
port: 3000
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,6 @@ impl Cursors {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
drop(vault_to_cursors); // Explicitly drop the lock before broadcasting to avoid deadlock
|
drop(vault_to_cursors); // Explicitly drop the lock before broadcasting to avoid deadlock
|
||||||
|
|
||||||
self.broadcast_cursors().await;
|
self.broadcast_cursors().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -70,17 +69,13 @@ impl Cursors {
|
||||||
|
|
||||||
pub fn start_background_task(self) {
|
pub fn start_background_task(self) {
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
self.run_backround_task().await;
|
loop {
|
||||||
|
self.remove_expired_cursors().await;
|
||||||
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run_backround_task(&self) {
|
|
||||||
loop {
|
|
||||||
self.remove_expired_cursors().await;
|
|
||||||
tokio::time::sleep(self.config.cursor_broadcast_interval).await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn remove_expired_cursors(&self) {
|
async fn remove_expired_cursors(&self) {
|
||||||
let mut vault_to_cursors = self.vault_to_cursors.lock().await;
|
let mut vault_to_cursors = self.vault_to_cursors.lock().await;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,7 @@ use serde::{Deserialize, Serialize};
|
||||||
use serde_with::serde_as;
|
use serde_with::serde_as;
|
||||||
|
|
||||||
use crate::consts::{
|
use crate::consts::{
|
||||||
DEFAULT_CURSOR_BROADCAST_INTERVAL, DEFAULT_CURSOR_TIMEOUT, DEFAULT_DATABASES_DIRECTORY_PATH,
|
DEFAULT_CURSOR_TIMEOUT, DEFAULT_DATABASES_DIRECTORY_PATH, DEFAULT_MAX_CONNECTIONS_PER_VAULT,
|
||||||
DEFAULT_MAX_CONNECTIONS_PER_VAULT,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[serde_with::serde_as]
|
#[serde_with::serde_as]
|
||||||
|
|
@ -21,13 +20,6 @@ pub struct DatabaseConfig {
|
||||||
#[serde(default = "default_cursor_timeout", rename = "cursor_timeout_seconds")]
|
#[serde(default = "default_cursor_timeout", rename = "cursor_timeout_seconds")]
|
||||||
#[serde_as(as = "serde_with::DurationSeconds<u64>")]
|
#[serde_as(as = "serde_with::DurationSeconds<u64>")]
|
||||||
pub cursor_timeout: Duration,
|
pub cursor_timeout: Duration,
|
||||||
|
|
||||||
#[serde(
|
|
||||||
default = "default_cursor_broadcast_interval",
|
|
||||||
rename = "cursor_broadcast_interval_seconds"
|
|
||||||
)]
|
|
||||||
#[serde_as(as = "serde_with::DurationSeconds<u64>")]
|
|
||||||
pub cursor_broadcast_interval: Duration,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_databases_directory_path() -> PathBuf {
|
fn default_databases_directory_path() -> PathBuf {
|
||||||
|
|
@ -45,18 +37,12 @@ fn default_cursor_timeout() -> Duration {
|
||||||
DEFAULT_CURSOR_TIMEOUT
|
DEFAULT_CURSOR_TIMEOUT
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_cursor_broadcast_interval() -> Duration {
|
|
||||||
debug!("Using default cursor broadcast interval: {DEFAULT_CURSOR_BROADCAST_INTERVAL:?}");
|
|
||||||
DEFAULT_CURSOR_BROADCAST_INTERVAL
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for DatabaseConfig {
|
impl Default for DatabaseConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
databases_directory_path: default_databases_directory_path(),
|
databases_directory_path: default_databases_directory_path(),
|
||||||
max_connections_per_vault: default_max_connections_per_vault(),
|
max_connections_per_vault: default_max_connections_per_vault(),
|
||||||
cursor_timeout: default_cursor_timeout(),
|
cursor_timeout: default_cursor_timeout(),
|
||||||
cursor_broadcast_interval: default_cursor_broadcast_interval(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ pub const DEFAULT_CONFIG_PATH: &str = "config.yml";
|
||||||
pub const DEFAULT_DATABASES_DIRECTORY_PATH: &str = "databases";
|
pub const DEFAULT_DATABASES_DIRECTORY_PATH: &str = "databases";
|
||||||
pub const DEFAULT_MAX_CONNECTIONS_PER_VAULT: u32 = 12;
|
pub const DEFAULT_MAX_CONNECTIONS_PER_VAULT: u32 = 12;
|
||||||
pub const DEFAULT_CURSOR_TIMEOUT: Duration = Duration::from_secs(60);
|
pub const DEFAULT_CURSOR_TIMEOUT: Duration = Duration::from_secs(60);
|
||||||
pub const DEFAULT_CURSOR_BROADCAST_INTERVAL: Duration = Duration::from_secs(1);
|
|
||||||
|
|
||||||
pub const DEFAULT_HOST: &str = "127.0.0.1";
|
pub const DEFAULT_HOST: &str = "127.0.0.1";
|
||||||
pub const DEFAULT_PORT: u16 = 3000;
|
pub const DEFAULT_PORT: u16 = 3000;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue