-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from eigr-labs/feat/try-again
Feat/try again
- Loading branch information
Showing
24 changed files
with
1,261 additions
and
798 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pub(crate) fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
tonic_build::configure() | ||
.build_server(false) | ||
.out_dir("src/domain") | ||
.compile(&["proto/domain.proto"], &["proto"])?; | ||
Ok(()) | ||
} |
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,15 @@ | ||
syntax = "proto3"; | ||
|
||
package domain; | ||
|
||
message State { | ||
repeated string languages = 1; | ||
} | ||
|
||
message Request { | ||
string language = 1; | ||
} | ||
|
||
message Reply { | ||
string response = 1; | ||
} |
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,18 @@ | ||
#[allow(clippy::derive_partial_eq_without_eq)] | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
pub struct State { | ||
#[prost(string, repeated, tag = "1")] | ||
pub languages: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, | ||
} | ||
#[allow(clippy::derive_partial_eq_without_eq)] | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
pub struct Request { | ||
#[prost(string, tag = "1")] | ||
pub language: ::prost::alloc::string::String, | ||
} | ||
#[allow(clippy::derive_partial_eq_without_eq)] | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
pub struct Reply { | ||
#[prost(string, tag = "1")] | ||
pub response: ::prost::alloc::string::String, | ||
} |
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 @@ | ||
pub mod domain; |
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,50 +1,26 @@ | ||
use prost_types::Any; | ||
use spawn_examples::domain::domain::{Reply, Request}; | ||
use spawn_rs::{context::Context, value::Value, Message}; | ||
|
||
use spawn_rs::{ | ||
action::Action, | ||
actor::{Actor, ActorSettings, Kind}, | ||
context::Context, | ||
serializer::Serializer, | ||
value::Value, | ||
Message, | ||
}; | ||
use log::info; | ||
|
||
pub struct Joe; | ||
pub fn set_language(msg: Message, ctx: Context) -> Value { | ||
info!("Actor msg: {:?}", msg); | ||
let value: Value = match msg.body::<Request>() { | ||
Ok(request) => { | ||
let lang = request.language; | ||
info!("Setlanguage To: {:?}", lang); | ||
let reply = Reply::default(); | ||
|
||
impl Serializer for Joe { | ||
fn decode(&mut self, _msg: prost_types::Any) -> Box<dyn std::any::Any> { | ||
todo!() | ||
} | ||
|
||
fn encode(&mut self, _msg: Box<dyn std::any::Any>) -> prost_types::Any { | ||
todo!() | ||
} | ||
} | ||
|
||
impl Actor for Joe { | ||
fn settings(&mut self) -> ActorSettings { | ||
ActorSettings::new() | ||
.name("joe".to_owned()) | ||
.kind(Kind::SINGLETON) | ||
.stateful(true) | ||
.actions(vec!["sum".to_string()]) | ||
.deactivated_timeout(30000) | ||
.snapshot_timeout(10000) | ||
.to_owned() | ||
} | ||
} | ||
|
||
impl Action for Joe { | ||
fn handle(&mut self, msg: Message, ctx: &mut Context) -> Value { | ||
match msg.action() { | ||
"sum" => Value::new() | ||
Value::new() | ||
.state(ctx.state().clone()) | ||
.response(Any::default()) | ||
.to_owned(), | ||
_ => Value::new() | ||
.state(Any::default()) | ||
.response(Any::default()) | ||
.to_owned(), | ||
.response(&Reply::default()) | ||
.to_owned() | ||
} | ||
} | ||
Err(e) => Value::new() | ||
.state(ctx.state().clone()) | ||
//.response(Any::default()) | ||
.to_owned(), | ||
}; | ||
|
||
return value; | ||
} |
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,5 @@ | ||
#[macro_use] | ||
extern crate log; | ||
extern crate prost_types; | ||
|
||
pub mod domain; |
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,19 +1,32 @@ | ||
extern crate env_logger; | ||
extern crate prost_types; | ||
extern crate tokio; | ||
extern crate rocket; | ||
|
||
mod joe; | ||
|
||
use joe::set_language; | ||
use spawn_rs::actor::{ActorDefinition, ActorSettings, Kind}; | ||
use spawn_rs::spawn::Spawn; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("debug")); | ||
|
||
#[rocket::main] | ||
async fn main() -> Result<(), rocket::Error> { | ||
Spawn::new() | ||
.system("spawn-system".to_string()) | ||
.port(8091) | ||
.add_actor(Box::new(joe::Joe {})) | ||
.create("spawn-system".to_string()) | ||
.with_actor( | ||
ActorDefinition::new() | ||
.with_settings( | ||
ActorSettings::new() | ||
.name("joe".to_owned()) | ||
.kind(Kind::NAMED) | ||
.stateful(true) | ||
.deactivated_timeout(30000) | ||
.snapshot_timeout(10000) | ||
.to_owned(), | ||
) | ||
.with_action("sum".to_owned(), set_language), | ||
) | ||
.start() | ||
.await; | ||
.await?; | ||
|
||
Ok(()) | ||
} |
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
Oops, something went wrong.