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