-
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.
* stash * stash * stash * stash: * stash * http output * stash
- Loading branch information
1 parent
241466d
commit 116eb42
Showing
21 changed files
with
1,669 additions
and
101 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,16 @@ | ||
[package] | ||
name = "scout-worker" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
scout-interpreter = { version = "0.6.0", path = "../scout-interpreter/" } | ||
actix-web = "4" | ||
tokio = { version = "1", features = ["full"] } | ||
serde = { version = "1.0.203", features = ["derive"] } | ||
toml = "0.8.16" | ||
lapin = { version = "2.5.0", default-features = false, features = ["native-tls"] } | ||
futures-lite = "2.3.0" | ||
serde_json = "1.0" | ||
tracing = "0.1.40" | ||
reqwest = "0.12.5" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use std::fs; | ||
|
||
use serde::Deserialize; | ||
|
||
use crate::WorkerError; | ||
|
||
const DFEAULT_CONFIG_FILE: &str = "scout.toml"; | ||
|
||
#[derive(Debug, Default, Deserialize)] | ||
pub struct Config { | ||
pub inputs: ConfigInputs, | ||
pub outputs: Option<ConfigOutputs>, | ||
} | ||
|
||
#[derive(Debug, Default, Deserialize)] | ||
pub struct ConfigOutputs { | ||
pub rmq: Option<ConfigRMQ>, | ||
pub http: Option<ConfigOutputHttp>, | ||
} | ||
|
||
#[derive(Debug, Default, Deserialize)] | ||
pub struct ConfigInputs { | ||
pub http: Option<ConfigInputHttp>, | ||
pub rmq: Option<ConfigRMQ>, | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub struct ConfigInputHttp { | ||
pub addr: String, | ||
pub port: usize, | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub enum OutputMethods { | ||
POST, | ||
PUT, | ||
PATCH, | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub struct ConfigOutputHttp { | ||
pub endpoint: String, | ||
pub method: OutputMethods, | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub struct ConfigRMQ { | ||
pub addr: String, | ||
pub queue: String, | ||
pub exchange: String, | ||
pub routing_key: String, | ||
} | ||
|
||
impl Config { | ||
pub fn load_file(path: Option<&str>) -> Result<Self, WorkerError> { | ||
let path = path.unwrap_or(DFEAULT_CONFIG_FILE); | ||
let content = | ||
fs::read_to_string(path).map_err(|e| WorkerError::ConfigError(e.to_string()))?; | ||
toml::from_str(&content).map_err(|e| WorkerError::ConfigError(e.to_string())) | ||
} | ||
} | ||
|
||
impl std::fmt::Display for OutputMethods { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::PATCH => write!(f, "PATCH"), | ||
Self::POST => write!(f, "POST"), | ||
Self::PUT => write!(f, "PUT"), | ||
} | ||
} | ||
} |
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,2 @@ | ||
pub mod sender; | ||
pub mod server; |
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,37 @@ | ||
use reqwest::Method; | ||
use tracing::info; | ||
|
||
use crate::config::OutputMethods; | ||
|
||
pub struct Sender { | ||
client: reqwest::Client, | ||
method: Method, | ||
endpoint: String, | ||
} | ||
|
||
impl Sender { | ||
pub fn new( | ||
method: &OutputMethods, | ||
endpoint: String, | ||
) -> Result<Self, Box<dyn std::error::Error>> { | ||
let client = reqwest::Client::new(); | ||
let method = Method::from_bytes(method.to_string().as_bytes())?; | ||
Ok(Self { | ||
client, | ||
method, | ||
endpoint, | ||
}) | ||
} | ||
|
||
pub async fn send(&self, payload: &str) -> Result<(), reqwest::Error> { | ||
info!("sending output to {} {}", self.method, self.endpoint); | ||
let req = self | ||
.client | ||
.request(self.method.clone(), &self.endpoint) | ||
.body(payload.to_owned()) | ||
.build()?; | ||
let res = self.client.execute(req).await?; | ||
info!("received response code {}", res.status()); | ||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.