-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hydro_cli): added basic wrapper for hydro deploy Maelstrom integ…
…ration
- Loading branch information
Ryan Alameddine
committed
Nov 18, 2023
1 parent
3136e0f
commit f84c542
Showing
19 changed files
with
1,406 additions
and
12 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
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,71 @@ | ||
use hydroflow::hydroflow_syntax; | ||
use hydroflow::util::cli::{ConnectedDirect, ConnectedSink, ConnectedSource}; | ||
use hydroflow::util::serialize_to_bytes; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::Value; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct EchoMsg { | ||
pub msg_id: Value, | ||
pub echo: String, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct EchoOkMsg { | ||
pub echo: String, | ||
pub in_reply_to: Value, | ||
} | ||
|
||
impl EchoMsg { | ||
/// Generate EchoOkMsg response to this EchoMsg | ||
fn response( | ||
EchoMsg { | ||
echo, | ||
msg_id: source_msg_id, | ||
}: Self, | ||
) -> EchoOkMsg { | ||
EchoOkMsg { | ||
echo, | ||
in_reply_to: source_msg_id, | ||
} | ||
} | ||
} | ||
|
||
#[hydroflow::main] | ||
async fn main() { | ||
let mut ports = hydroflow::util::cli::init().await; | ||
|
||
// TODO: use ConnectedDemux? | ||
let echo_in = ports | ||
.port("echo_in") | ||
.connect::<ConnectedDirect>() | ||
.await | ||
.into_source(); | ||
let echo_out = ports | ||
.port("echo_out") | ||
.connect::<ConnectedDirect>() | ||
.await | ||
.into_sink(); | ||
|
||
let df = hydroflow_syntax! { | ||
input = source_stream(echo_in) | ||
-> map(Result::unwrap) | ||
-> map(|x| x.to_vec()) | ||
-> map(String::from_utf8) | ||
-> map(Result::unwrap); | ||
|
||
output = map(|x| serde_json::to_string(&x)) | ||
-> map(Result::unwrap) | ||
-> map(serialize_to_bytes) | ||
-> dest_sink(echo_out); | ||
|
||
|
||
input | ||
-> map(|x| serde_json::from_str::<EchoMsg>(&x).unwrap()) | ||
//-> map(|x| EchoMsg {msg_id: x.msg_id, echo: x.echo + "hi"}) | ||
-> map(EchoMsg::response) | ||
-> output; | ||
}; | ||
|
||
hydroflow::util::cli::launch_flow(df).await; | ||
} |
Oops, something went wrong.