Just use a single function to spawn Gecko Driver
This commit is contained in:
parent
7311b09f28
commit
b7ff296c65
37
src/main.rs
37
src/main.rs
|
@ -32,26 +32,20 @@ struct Config {
|
||||||
password: String,
|
password: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
fn spawn_driver(port: u16) -> Result<Child> {
|
||||||
struct GeckoDriver(Child);
|
// This is taken from the webdriver-client crate.
|
||||||
|
let child = Command::new("geckodriver")
|
||||||
|
.arg("--port")
|
||||||
|
.arg(format!("{}", port))
|
||||||
|
.stdin(Stdio::null())
|
||||||
|
.stderr(Stdio::null())
|
||||||
|
.stdout(Stdio::null())
|
||||||
|
.kill_on_drop(true)
|
||||||
|
.spawn()?;
|
||||||
|
|
||||||
impl GeckoDriver {
|
thread::sleep(Duration::new(1, 500));
|
||||||
pub fn spawn(port: u16) -> Result<Self> {
|
|
||||||
// This is taken from the webdriver-client crate.
|
|
||||||
let child = Command::new("geckodriver")
|
|
||||||
// .arg("-v")
|
|
||||||
.arg("--port")
|
|
||||||
.arg(format!("{}", port))
|
|
||||||
.stdin(Stdio::null())
|
|
||||||
.stderr(Stdio::null())
|
|
||||||
.stdout(Stdio::null())
|
|
||||||
.kill_on_drop(true)
|
|
||||||
.spawn()?;
|
|
||||||
|
|
||||||
thread::sleep(Duration::new(1, 500));
|
Ok(child)
|
||||||
|
|
||||||
Ok(GeckoDriver(child))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Serialize)]
|
#[derive(Clone, Copy, Debug, Serialize)]
|
||||||
|
@ -171,8 +165,9 @@ fn rocket() -> Rocket {
|
||||||
|
|
||||||
#[rocket::main]
|
#[rocket::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let gecko_driver =
|
let driver_proc =
|
||||||
GeckoDriver::spawn(GECKO_DRIVER_PORT).expect("Could not find/start the Gecko Driver");
|
spawn_driver(GECKO_DRIVER_PORT).expect("Could not find/start the Gecko Driver");
|
||||||
|
|
||||||
let (tx, rx) = tokio::sync::oneshot::channel();
|
let (tx, rx) = tokio::sync::oneshot::channel();
|
||||||
let updater = tokio::spawn(update_loop(rx));
|
let updater = tokio::spawn(update_loop(rx));
|
||||||
|
|
||||||
|
@ -183,5 +178,5 @@ async fn main() {
|
||||||
.expect("Could not send update loop shutdown signal");
|
.expect("Could not send update loop shutdown signal");
|
||||||
let _result = updater.await;
|
let _result = updater.await;
|
||||||
|
|
||||||
drop(gecko_driver);
|
drop(driver_proc);
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue