-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18a18ba
commit d893c99
Showing
10 changed files
with
195 additions
and
79 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Scout-worker is a processing framework for ScoutLang. It provides multiple input/output types that are driven via configuration. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,81 @@ | ||
use std::{env, fs, process::Command}; | ||
|
||
use repl::run_repl; | ||
use scout_interpreter::{builder::InterpreterBuilder, env::Env, eval::ScrapeResultsPtr, EnvVars}; | ||
use scout_interpreter::{ | ||
builder::InterpreterBuilder, env::Env, eval::ScrapeResultsPtr, EnvVars, Interpreter, | ||
}; | ||
|
||
mod repl; | ||
|
||
async fn run( | ||
file: Option<String>, | ||
results: ScrapeResultsPtr, | ||
interpreter: &Interpreter, | ||
// results: ScrapeResultsPtr, | ||
) -> Result<(), Box<dyn std::error::Error>> { | ||
let env = Env::default(); | ||
// let env = Env::default(); | ||
match file { | ||
None => run_repl(results, env).await, | ||
None => run_repl(interpreter).await, | ||
Some(f) => { | ||
let contents = fs::read_to_string(f)?; | ||
let interpret = InterpreterBuilder::default() | ||
.with_results(results) | ||
.build() | ||
.await?; | ||
if let Err(e) = interpret.eval(&contents).await { | ||
// let interpret = InterpreterBuilder::default() | ||
// .with_results(results) | ||
// .build() | ||
// .await?; | ||
if let Err(e) = interpreter.eval(&contents).await { | ||
println!("Interpeter error: {:?}", e); | ||
} | ||
|
||
interpret.finalize().await; | ||
|
||
Ok(()) | ||
} | ||
} | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let env_vars = envy::from_env::<EnvVars>().expect("error loading env config"); | ||
// let env_vars = envy::from_env::<EnvVars>().expect("error loading env config"); | ||
let args: Vec<String> = env::args().collect(); | ||
|
||
let child = Command::new("geckodriver") | ||
.arg("--port") | ||
.arg(env_vars.port().to_string()) | ||
.stdout(std::process::Stdio::null()) | ||
.stderr(std::process::Stdio::null()) | ||
.spawn() | ||
.expect("error spinning up driver process"); | ||
// let child = Command::new("geckodriver") | ||
// .arg("--port") | ||
// .arg(env_vars.port().to_string()) | ||
// .stdout(std::process::Stdio::null()) | ||
// .stderr(std::process::Stdio::null()) | ||
// .spawn() | ||
// .expect("error spinning up driver process"); | ||
|
||
// sleep to allow driver to start | ||
std::thread::sleep(std::time::Duration::from_millis(50)); | ||
// // sleep to allow driver to start | ||
// std::thread::sleep(std::time::Duration::from_millis(50)); | ||
|
||
let results = ScrapeResultsPtr::default(); | ||
if let Err(e) = run(args.get(1).cloned(), results.clone()).await { | ||
// let results = ScrapeResultsPtr::default(); | ||
let interpreter = InterpreterBuilder::default() | ||
.build() | ||
.await | ||
.expect("failed to build interpreter"); | ||
if let Err(e) = run(args.get(1).cloned(), &interpreter).await { | ||
println!("Error: {}", e); | ||
} | ||
let json_results = results.lock().await.to_json(); | ||
let json_results = interpreter.results().lock().await.to_json(); | ||
println!("{}", json_results); | ||
|
||
#[cfg(target_os = "windows")] | ||
let mut kill = Command::new("taskkill") | ||
.arg("/PID") | ||
.arg(&child.id().to_string()) | ||
.stdout(std::process::Stdio::null()) | ||
.stderr(std::process::Stdio::null()) | ||
.arg("/F") | ||
.spawn() | ||
.expect("error sending driver kill"); | ||
interpreter.close().await; | ||
|
||
// #[cfg(target_os = "windows")] | ||
// let mut kill = Command::new("taskkill") | ||
// .arg("/PID") | ||
// .arg(&child.id().to_string()) | ||
// .stdout(std::process::Stdio::null()) | ||
// .stderr(std::process::Stdio::null()) | ||
// .arg("/F") | ||
// .spawn() | ||
// .expect("error sending driver kill"); | ||
|
||
#[cfg(not(target_os = "windows"))] | ||
let mut kill = Command::new("kill") | ||
.args(["-s", "TERM", &child.id().to_string()]) | ||
.stdout(std::process::Stdio::null()) | ||
.stderr(std::process::Stdio::null()) | ||
.spawn() | ||
.expect("error sending driver kill"); | ||
// #[cfg(not(target_os = "windows"))] | ||
// let mut kill = Command::new("kill") | ||
// .args(["-s", "TERM", &child.id().to_string()]) | ||
// .stdout(std::process::Stdio::null()) | ||
// .stderr(std::process::Stdio::null()) | ||
// .spawn() | ||
// .expect("error sending driver kill"); | ||
|
||
kill.wait().expect("error waiting for driver kill"); | ||
// kill.wait().expect("error waiting for driver kill"); | ||
} |
Oops, something went wrong.