Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmindlin committed Aug 6, 2024
1 parent 013b877 commit e9d04a3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 65 deletions.
1 change: 1 addition & 0 deletions scout-worker/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct ConfigRMQ {
pub addr: String,
pub queue: String,
pub exchange: String,
pub routing_key: String,
}

impl Config {
Expand Down
12 changes: 11 additions & 1 deletion scout-worker/src/rmq/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use futures_lite::StreamExt;
use lapin::{
options::{
BasicAckOptions, BasicConsumeOptions, BasicNackOptions, ExchangeDeclareOptions,
QueueDeclareOptions,
QueueBindOptions, QueueDeclareOptions,
},
types::FieldTable,
Channel, Connection, ConnectionProperties, ExchangeKind,
Expand Down Expand Up @@ -50,6 +50,16 @@ impl Consumer {
)
.await?;

chann
.queue_bind(
&config.queue,
&config.exchange,
&config.routing_key,
QueueBindOptions::default(),
FieldTable::default(),
)
.await?;

Ok(Self {
chann,
queue: config.queue.clone(),
Expand Down
19 changes: 16 additions & 3 deletions scout-worker/src/rmq/producer.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::fmt::Display;

use lapin::{
options::{ExchangeDeclareOptions, QueueDeclareOptions},
options::{BasicPublishOptions, ExchangeDeclareOptions, QueueDeclareOptions},
types::FieldTable,
Channel, Connection, ConnectionProperties, ExchangeKind,
BasicProperties, Channel, Connection, ConnectionProperties, ExchangeKind,
};

use crate::config::ConfigRMQ;
Expand All @@ -16,6 +16,8 @@ pub enum ProducerError {
pub struct Producer {
chann: Channel,
queue: String,
exchange: String,
out_key: String,
}

impl Producer {
Expand Down Expand Up @@ -43,11 +45,22 @@ impl Producer {
Ok(Self {
chann,
queue: config.queue.clone(),
exchange: config.exchange.clone(),
out_key: config.routing_key.clone(),
})
}

pub async fn send(&self, payload: String) -> Result<(), ProducerError> {
unimplemented!()
self.chann
.basic_publish(
&self.exchange,
&self.out_key,
BasicPublishOptions::default(),
&payload,

Check failure on line 59 in scout-worker/src/rmq/producer.rs

View workflow job for this annotation

GitHub Actions / test

mismatched types
BasicProperties::default(),
)
.await?;
Ok(())
}
}

Expand Down
45 changes: 2 additions & 43 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
use std::{env, fs, process::Command};
use std::{env, fs};

use repl::run_repl;
use scout_interpreter::{
builder::InterpreterBuilder, env::Env, eval::ScrapeResultsPtr, EnvVars, Interpreter,
};
use scout_interpreter::{builder::InterpreterBuilder, Interpreter};

mod repl;

async fn run(
file: Option<String>,
interpreter: &Interpreter,
// results: ScrapeResultsPtr,
) -> Result<(), Box<dyn std::error::Error>> {
// let env = Env::default();
match file {
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) = interpreter.eval(&contents).await {
println!("Interpeter error: {:?}", e);
}
Expand All @@ -32,21 +24,8 @@ async fn run(

#[tokio::main]
async fn main() {
// 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");

// // sleep to allow driver to start
// std::thread::sleep(std::time::Duration::from_millis(50));

// let results = ScrapeResultsPtr::default();
let interpreter = InterpreterBuilder::default()
.build()
.await
Expand All @@ -58,24 +37,4 @@ async fn main() {
println!("{}", json_results);

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");

// kill.wait().expect("error waiting for driver kill");
}
20 changes: 2 additions & 18 deletions src/repl.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
use std::sync::Arc;

use futures::lock::Mutex;
use rustyline::{error::ReadlineError, Editor};
use scout_interpreter::{
builder::InterpreterBuilder, env::Env, eval::ScrapeResultsPtr, Interpreter,
};
use scout_interpreter::Interpreter;

const PROMPT: &str = ">> ";

pub async fn run_repl(
// results: ScrapeResultsPtr,
interpreter: &Interpreter, // env: Env,
) -> Result<(), Box<dyn std::error::Error>> {
pub async fn run_repl(interpreter: &Interpreter) -> Result<(), Box<dyn std::error::Error>> {
let mut rl = Editor::<()>::new();
// let env = Arc::new(Mutex::new(env));

// let interpreter = InterpreterBuilder::default()
// .with_env(env.clone())
// .with_results(results.clone())
// .build()
// .await?;
if rl.load_history("history.txt").is_err() {
println!("No previous history.");
}
Expand Down Expand Up @@ -51,6 +36,5 @@ pub async fn run_repl(
}
}
rl.save_history("history.txt").unwrap();
// interpreter.close().await;
Ok(())
}

0 comments on commit e9d04a3

Please sign in to comment.