-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Download logs #222
Download logs #222
Changes from all commits
7587eff
5b58ffc
2ea11dd
a185875
3c29a2a
8bff5d0
45b070e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use crate::{ | ||
get_player_dir, player_config_exists, CONDUCTOR_STDERR_LOG_FILENAME, | ||
CONDUCTOR_STDOUT_LOG_FILENAME, LAIR_STDERR_LOG_FILENAME, | ||
}; | ||
use snafu::{ResultExt, Snafu}; | ||
use trycp_api::{DownloadLogsResponse, MessageResponse, TryCpServerResponse}; | ||
|
||
#[derive(Debug, Snafu)] | ||
pub(crate) enum DownloadLogsError { | ||
#[snafu(display("No player with this ID is configured {}", id))] | ||
PlayerNotConfigured { id: String }, | ||
#[snafu(display("Could not read lair stderr log for player with ID {}: {}", id, source))] | ||
LairStdErr { id: String, source: std::io::Error }, | ||
#[snafu(display( | ||
"Could not read holochain stdout log for player with ID {}: {}", | ||
id, | ||
source | ||
))] | ||
HolochainStdout { id: String, source: std::io::Error }, | ||
#[snafu(display( | ||
"Could not read holochain stderr log for player with ID {}: {}", | ||
id, | ||
source | ||
))] | ||
HolochainStderr { id: String, source: std::io::Error }, | ||
#[snafu(display("Could not serialize response: {}", source))] | ||
SerializeResponse { source: rmp_serde::encode::Error }, | ||
} | ||
|
||
pub(crate) fn download_logs(id: String) -> Result<MessageResponse, DownloadLogsError> { | ||
if !player_config_exists(&id) { | ||
return Err(DownloadLogsError::PlayerNotConfigured { id }); | ||
} | ||
|
||
let player_dir = get_player_dir(&id); | ||
|
||
let lair_stderr = player_dir.join(LAIR_STDERR_LOG_FILENAME); | ||
let lair_stderr = std::fs::read(&lair_stderr).context(LairStdErr { id: id.clone() })?; | ||
|
||
let conductor_stdout = player_dir.join(CONDUCTOR_STDOUT_LOG_FILENAME); | ||
let conductor_stdout = | ||
std::fs::read(&conductor_stdout).context(HolochainStdout { id: id.clone() })?; | ||
|
||
let conductor_stderr = player_dir.join(CONDUCTOR_STDERR_LOG_FILENAME); | ||
let conductor_stderr = std::fs::read(&conductor_stderr).context(HolochainStderr { id })?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are we cool with these blocking whatever thread happens to be running? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The entire function is being run on a blocking thread -> https://github.com/holochain/tryorama/pull/222/files#diff-db8eb8bbb5e02b33e796b281bce321e0d781f68204bac8f217e5eddbe9e34319R256 This seems to be the established pattern for the trycp_server, to offload the entire function if it's not async |
||
|
||
Ok(MessageResponse::Bytes( | ||
rmp_serde::to_vec_named(&TryCpServerResponse::DownloadLogs(DownloadLogsResponse { | ||
lair_stderr, | ||
conductor_stdout, | ||
conductor_stderr, | ||
})) | ||
.context(SerializeResponse)?, | ||
)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some type f*ry required to let the JS client decode these types. It's the first time we've returned anything more complicated than a string and the JS client has a special case for strings.