Skip to content

Commit

Permalink
Fix server issue in docker (#1743)
Browse files Browse the repository at this point in the history
fixed server

Co-authored-by: Ben Steer <[email protected]>
  • Loading branch information
miratepuffin and Ben Steer authored Sep 3, 2024
1 parent 47e3329 commit d082915
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies = [
"requests >= 2.31.0",
"gql[all] == 3.5.0",
"matplotlib >= 3.4.3",
"ipywidgets >= 8.1.5",
]


Expand Down
5 changes: 4 additions & 1 deletion python/tests/graphql/edit_graph/test_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ def test_failed_server_start_in_time():
def test_wrong_url():
with pytest.raises(Exception) as excinfo:
client = RaphtoryClient("http://broken_url.com")
assert str(excinfo.value) == "Could not connect to the given server - no response"
assert (
str(excinfo.value)
== "Could not connect to the given server - no response --error sending request for url (http://broken_url.com/)"
)


def test_successful_server_start_in_time():
Expand Down
7 changes: 4 additions & 3 deletions raphtory-graphql/src/python/client/raphtory_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ impl PyRaphtoryClient {
)))
}
}
Err(_) => Err(PyValueError::new_err(
"Could not connect to the given server - no response",
)),
Err(e) => Err(PyValueError::new_err(format!(
"Could not connect to the given server - no response --{}",
e.to_string()
))),
}
}

Expand Down
12 changes: 7 additions & 5 deletions raphtory-graphql/src/python/server/running_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct PyRunningGraphServer {
pub(crate) struct ServerHandler {
pub(crate) join_handle: JoinHandle<IoResult<()>>,
sender: CrossbeamSender<BridgeCommand>,
pub(crate) client: PyRaphtoryClient,
port: u16,
}

impl PyRunningGraphServer {
Expand All @@ -29,13 +29,11 @@ impl PyRunningGraphServer {
sender: CrossbeamSender<BridgeCommand>,
port: u16,
) -> PyResult<Self> {
let url = format!("http://localhost:{port}");
let server_handler = Some(ServerHandler {
join_handle,
sender,
client: PyRaphtoryClient::new(url)?,
port,
});

Ok(PyRunningGraphServer { server_handler })
}

Expand Down Expand Up @@ -83,7 +81,11 @@ impl PyRunningGraphServer {
#[pymethods]
impl PyRunningGraphServer {
pub(crate) fn get_client(&self) -> PyResult<PyRaphtoryClient> {
self.apply_if_alive(|handler| Ok(handler.client.clone()))
self.apply_if_alive(|handler| {
let port = handler.port;
let url = format!("http://localhost:{port}");
Ok(PyRaphtoryClient::new(url)?)
})
}

/// Stop the server and wait for it to finish
Expand Down
6 changes: 2 additions & 4 deletions raphtory-graphql/src/python/server/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,8 @@ impl PyGraphServer {

let mut server = PyRunningGraphServer::new(join_handle, sender, port)?;
if let Some(server_handler) = &server.server_handler {
match PyRunningGraphServer::wait_for_server_online(
&server_handler.client.url,
timeout_ms,
) {
let url = format!("http://localhost:{port}");
match PyRunningGraphServer::wait_for_server_online(&url, timeout_ms) {
Ok(_) => return Ok(server),
Err(e) => {
PyRunningGraphServer::stop_server(&mut server, py)?;
Expand Down

0 comments on commit d082915

Please sign in to comment.