-
Couldn't load subscription status.
- Fork 2
Headless runner for console[CPP-318][CPP-313]. #123
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
Conversation
| /// - `connection_state`: The Server state to start a specific connection. | ||
| /// - `client_send`: Client Sender channel for communication from backend to frontend. | ||
| /// - `shared_state`: The shared state for validating another connection is not already running. | ||
| pub fn handle_cli(opt: CliOptions, connection_state: &ConnectionState, shared_state: SharedState) { |
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.
This is simply moved out from server.rs, no other changes.
console_backend/src/shared_state.rs
Outdated
| pub fn backend_recv_thread( | ||
| connection_state: ConnectionState, | ||
| client_send: ClientSender, | ||
| server_recv: channel::Receiver<Vec<u8>>, | ||
| shared_state: SharedState, | ||
| ) { |
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.
This is simply moved out from server.rs, no other changes.
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.
Concept wise I'm not keen on moving this here, I think we should disable Python stuff in server.rs, e.g.:
Or just move it into it's own module server_recv_thread.rs
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.
Done. I like what you did in your PR of moving the py03 stuff to a non default feature. So as to no duplicate some of your work I just set up a server_recv_thread.rs file.
console_backend/src/bin/headless.rs
Outdated
| if opt.input.is_none() { | ||
| eprintln!("\nRunning in headless mode only command line options work."); | ||
| eprintln!("Help:"); | ||
| eprintln!("\tcargo make headless-run -- --help"); |
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.
Let's not reference cargo make here since it's part of the build system
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.
Done.
console_backend/src/bin/headless.rs
Outdated
| backend_recv_thread(connection_state, client_send, server_recv, shared_state); | ||
| s.spawn(move |_| { | ||
| loop { | ||
| if client_recv.recv().is_err() { |
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.
Can we write these message to the terminal or a log file?
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.
Done. Looks like the files are pretty small too so no need for rotating. I threw in a snap compression wrapper around the writer.
console_backend/src/shared_state.rs
Outdated
| pub fn backend_recv_thread( | ||
| connection_state: ConnectionState, | ||
| client_send: ClientSender, | ||
| server_recv: channel::Receiver<Vec<u8>>, | ||
| shared_state: SharedState, | ||
| ) { |
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.
Concept wise I'm not keen on moving this here, I think we should disable Python stuff in server.rs, e.g.:
Or just move it into it's own module server_recv_thread.rs
console_backend/src/types.rs
Outdated
| // use crate::update_tab::UpdateTabUpdate; | ||
| // use crate::utils::{mm_to_m, ms_to_sec, set_connected_frontend}; | ||
|
|
||
| // use anyhow::{Context, Result as AHResult}; |
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.
Please don't check in commented out code
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.
Removed. My mistake.
| impl Directory { | ||
| pub fn new_data_directory() -> Directory { | ||
| Directory { | ||
| path: create_data_dir().unwrap(), |
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.
Not related to this PR, but we should log a bug/Jira for this since it's ignoring an error for a file system operation (which can fail for many many reasons) so we should handle and report the error instead of .unwraping and potentially panicking.
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.
Set up a ticket:
https://swift-nav.atlassian.net/browse/CPP-320
console_backend/src/log_panel.rs
Outdated
|
|
||
| for (idx, item) in slice.iter().enumerate() { | ||
| if self.debug { | ||
| println!("{}", item); |
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.
eprintln! maybe?
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.
Done.
console_backend/src/bin/headless.rs
Outdated
| let opt = CliOptions::from_filtered_cli(); | ||
| let shared_state = SharedState::new(); | ||
| let connection_state = ConnectionState::new(client_send.clone(), shared_state.clone()); | ||
| if opt.input.is_none() { |
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.
How about moving the help stuff to the top, something like
fn main() -> Result<()> {
let opt = CliOptions::from_filtered_cli();
if opt.input.is_none() {
eprintln!("\n\
Running in headless mode only command line options work.\n\
Help:\n\
\tcargo make headless-run -- --help\n\
Usage:\n\
\tcargo make headless-run -- tcp piksi-relay-bb9f2b10e53143f4a816a11884e679cf.ce.swiftnav.com --port=55555"
);
return Ok(());
}
...
}to keep the main logic a little cleaner
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.
Done.
console_backend/src/bin/headless.rs
Outdated
| } | ||
| } | ||
| }) | ||
| .join().unwrap(); |
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.
You don't typically have to manually call join() on threads created with scope.spawn(..). the thread is automatically joined before the scope ends (that's why it can borrow things)
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.
Done. I should probably remove the join in the process_messages for the update tab as well.
Co-authored-by: Jason Mobarak <[email protected]>
Implements
debugparameter which indicates whether or not to print the log messages to the terminal in addition to over capnproto.