Skip to content

Conversation

@john-michaelburke
Copy link
Collaborator

@john-michaelburke john-michaelburke commented Sep 15, 2021

Implements

  • Creates a binary for running the console headless without python or qml frontend.
  • Moves the shared_state and all subtypes into a "shared_state" module.
  • Fixes all breaks from moving shared_state module.
  • Slight change to our logging module to accept a debug parameter which indicates whether or not to print the log messages to the terminal in addition to over capnproto.
  • Moves the handle_cli function from server.rs -> cli_option.rs
  • Moves the backend_recv_thread from server.rs -> shared_state.rs (Couldn't think of a more appropriate location for this function as mostly just pushes updates to shared_state).
  • Adds a makefile command to run headless quicker:
Running in headless mode only command line options work.
Help:
        cargo make headless-run -- --help
Usage:
        cargo make headless-run -- tcp piksi-relay-bb9f2b10e53143f4a816a11884e679cf.ce.swiftnav.com --port=55555

/// - `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) {
Copy link
Collaborator Author

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.

Comment on lines 712 to 717
pub fn backend_recv_thread(
connection_state: ConnectionState,
client_send: ClientSender,
server_recv: channel::Receiver<Vec<u8>>,
shared_state: SharedState,
) {
Copy link
Collaborator Author

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.

Copy link
Contributor

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

Copy link
Collaborator Author

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.

@john-michaelburke john-michaelburke marked this pull request as ready for review September 15, 2021 22:24
@john-michaelburke john-michaelburke requested a review from a team September 15, 2021 22:29
if opt.input.is_none() {
eprintln!("\nRunning in headless mode only command line options work.");
eprintln!("Help:");
eprintln!("\tcargo make headless-run -- --help");
Copy link
Contributor

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

backend_recv_thread(connection_state, client_send, server_recv, shared_state);
s.spawn(move |_| {
loop {
if client_recv.recv().is_err() {
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Comment on lines 712 to 717
pub fn backend_recv_thread(
connection_state: ConnectionState,
client_send: ClientSender,
server_recv: channel::Receiver<Vec<u8>>,
shared_state: SharedState,
) {
Copy link
Contributor

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

// use crate::update_tab::UpdateTabUpdate;
// use crate::utils::{mm_to_m, ms_to_sec, set_connected_frontend};

// use anyhow::{Context, Result as AHResult};
Copy link
Contributor

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

Copy link
Collaborator Author

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(),
Copy link
Contributor

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


for (idx, item) in slice.iter().enumerate() {
if self.debug {
println!("{}", item);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eprintln! maybe?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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() {
Copy link
Contributor

@notoriaga notoriaga Sep 16, 2021

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
}
})
.join().unwrap();
Copy link
Contributor

@notoriaga notoriaga Sep 16, 2021

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)

Copy link
Collaborator Author

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.

@john-michaelburke john-michaelburke merged commit e1786a3 into main Sep 17, 2021
@john-michaelburke john-michaelburke deleted the john-michaelburke/headless branch September 17, 2021 17:33
@john-michaelburke john-michaelburke changed the title Headless runner for console[CPP-318]. Headless runner for console[CPP-318][CPP-313]. Sep 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants