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
|
||||||
|
}
|
||||||
|
|
19
src/main.rs
19
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,11 +40,12 @@ 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();
|
||||||
|
signal_hook::flag::register(signal_hook::consts::SIGTERM, Arc::clone(&term)).unwrap();
|
||||||
|
loop {
|
||||||
|
if term.load(Ordering::Relaxed) {
|
||||||
println!();
|
println!();
|
||||||
println!("closing down");
|
println!("closing down");
|
||||||
static_handle.abort();
|
static_handle.abort();
|
||||||
|
@ -47,6 +53,7 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||||
chr.exit().expect("failed killing chromedriver");
|
chr.exit().expect("failed killing chromedriver");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue