Skip to content

Commit

Permalink
refactor: add logic for reconnect of spacetime db websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
ResuBaka committed Mar 6, 2025
1 parent b5f6bf1 commit 43ade71
Show file tree
Hide file tree
Showing 3 changed files with 882 additions and 843 deletions.
5 changes: 5 additions & 0 deletions rust/api-server/api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ pub(crate) struct CliConfigParameters {
pub(crate) database_url: Option<String>,
pub(crate) storage_path: Option<String>,
pub(crate) config_path: Option<String>,
pub(crate) live_updates_ws: Option<bool>,
}

impl Config {
Expand Down Expand Up @@ -456,6 +457,10 @@ impl Config {
cli_overrides = cli_overrides.set_default("storage_path", storage_path)?;
}

if let Some(live_updates_ws) = cli_config_parameters.live_updates_ws {
cli_overrides = cli_overrides.set_default("live_updates_ws", live_updates_ws)?;
}

config.add_source(cli_overrides.build()?)
} else {
config
Expand Down
20 changes: 6 additions & 14 deletions rust/api-server/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,9 @@ async fn start(database_connection: DatabaseConnection, config: Config) -> anyho

let app = create_app(&config, state.clone(), prometheus);

let websocket_url = config.weboosocket_url();
let websocket_password = config.spacetimedb.password.clone();
let websocket_username = config.spacetimedb.username.clone();
let database_name = config.spacetimedb.database.clone();

if config.live_updates_ws {
let tmp_config = config.clone();
websocket::start_websocket_bitcraft_logic(
websocket_url,
websocket_password,
websocket_username,
database_name,
tmp_config,
tx,
state.clone(),
);
websocket::start_websocket_bitcraft_logic(tmp_config, tx, state.clone());
}

let server_url = config.server_url();
Expand Down Expand Up @@ -967,6 +954,9 @@ you should provide the directory of that submodule.",

#[arg(long, help = "Storage path")]
storage_path: Option<String>,

#[arg(long, help = "Live updates")]
live_updates_ws: Option<bool>,
},
Download {
#[command(subcommand)]
Expand Down Expand Up @@ -994,10 +984,12 @@ pub async fn main() -> anyhow::Result<()> {
port,
host,
storage_path,
live_updates_ws,
} => {
cli_config_parameters.host = host.clone();
cli_config_parameters.port = *port;
cli_config_parameters.storage_path = storage_path.clone();
cli_config_parameters.live_updates_ws = *live_updates_ws;
}
}

Expand Down
Loading

0 comments on commit 43ade71

Please sign in to comment.