fixed windows builds
This commit is contained in:
parent
7eecbe0687
commit
60f8f3ed87
|
@ -45,7 +45,7 @@ impl Driver {
|
|||
|
||||
// Check if chromedriver has exited
|
||||
sys_info.refresh_all();
|
||||
if let None = sys_info.process(Pid::from(child_id.clone() as i32)) {
|
||||
if let None = sys_info.process(Pid::from(to_pid(child_id.clone()))) {
|
||||
let status_code = child.wait()?;
|
||||
println!("{}", status_code.code().unwrap());
|
||||
return Err(anyhow::anyhow!(
|
||||
|
@ -64,3 +64,13 @@ impl Driver {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
fn to_pid(v: u32) -> usize {
|
||||
v as usize
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn to_pid(v: u32) -> i32 {
|
||||
v as i32
|
||||
}
|
||||
|
|
31
src/main.rs
31
src/main.rs
|
@ -2,13 +2,18 @@ mod botdriver;
|
|||
mod browser;
|
||||
mod chromedriver;
|
||||
mod webserve;
|
||||
use std::io::{self, Write};
|
||||
use std::{
|
||||
io::{self, Write},
|
||||
sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
Arc,
|
||||
},
|
||||
};
|
||||
|
||||
use botdriver::BotDriver;
|
||||
use browser::BrowserSession;
|
||||
use chromedriver::Driver;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use signal_hook::iterator::Signals;
|
||||
|
||||
const STATIC_ADDR: &str = "127.0.0.1:8010";
|
||||
|
||||
|
@ -35,17 +40,19 @@ async fn main() -> Result<(), anyhow::Error> {
|
|||
println!("# starting frc #");
|
||||
println!("################");
|
||||
tokio::spawn(async move {
|
||||
let mut signals =
|
||||
Signals::new(&[signal_hook::consts::SIGINT, signal_hook::consts::SIGTERM])
|
||||
.expect("could not init listen signals");
|
||||
let term = Arc::new(AtomicBool::new(false));
|
||||
|
||||
for _ in signals.forever() {
|
||||
println!();
|
||||
println!("closing down");
|
||||
static_handle.abort();
|
||||
driver.stop().await.expect("failed killing browser");
|
||||
chr.exit().expect("failed killing chromedriver");
|
||||
break;
|
||||
signal_hook::flag::register(signal_hook::consts::SIGINT, Arc::clone(&term)).unwrap();
|
||||
signal_hook::flag::register(signal_hook::consts::SIGTERM, Arc::clone(&term)).unwrap();
|
||||
loop {
|
||||
if term.load(Ordering::Relaxed) {
|
||||
println!();
|
||||
println!("closing down");
|
||||
static_handle.abort();
|
||||
driver.stop().await.expect("failed killing browser");
|
||||
chr.exit().expect("failed killing chromedriver");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::process::exit(0);
|
||||
|
|
Loading…
Reference in New Issue