-
Notifications
You must be signed in to change notification settings - Fork 12
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
Showing
10 changed files
with
120 additions
and
36 deletions.
There are no files selected for viewing
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,29 @@ | ||
[package] | ||
name = "bios-mw-event-client" | ||
version.workspace = true | ||
authors.workspace = true | ||
homepage.workspace = true | ||
documentation.workspace = true | ||
repository.workspace = true | ||
license.workspace = true | ||
edition.workspace = true | ||
readme.workspace = true | ||
publish.workspace = true | ||
|
||
[lib] | ||
name = "bios_mw_event_client" | ||
path = "src/lib.rs" | ||
|
||
[dependencies] | ||
serde.workspace = true | ||
|
||
tardis = { workspace = true, features = [ | ||
"reldb-postgres", | ||
"web-server", | ||
"ws-client", | ||
] } | ||
|
||
bios-sdk-invoke = { version = "0.2.0", path = "../../../frontend/sdks/invoke", features = [ | ||
"spi_log", | ||
"event", | ||
], default-features = false } |
22 changes: 22 additions & 0 deletions
22
backend/middlewares/event-client/src/event_client_config.rs
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,22 @@ | ||
use bios_sdk_invoke::invoke_config::InvokeConfig; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
#[serde(default)] | ||
pub struct EventClientConfig { | ||
pub max_retry_times: Option<usize>, | ||
pub enable: bool, | ||
pub retry_duration_ms: u32, | ||
pub invoke: InvokeConfig, | ||
} | ||
|
||
impl Default for EventClientConfig { | ||
fn default() -> Self { | ||
Self { | ||
max_retry_times: None, | ||
enable: false, | ||
retry_duration_ms: 5000, | ||
invoke: InvokeConfig::default(), | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
backend/middlewares/event-client/src/event_client_initializer.rs
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,30 @@ | ||
use crate::event_client_config::EventClientConfig; | ||
use bios_sdk_invoke::clients::event_client::init_client_node; | ||
use bios_sdk_invoke::invoke_initializer; | ||
use std::time::Duration; | ||
use tardis::tracing::{self, instrument}; | ||
use tardis::{ | ||
basic::{dto::TardisContext, result::TardisResult}, | ||
TardisFuns, | ||
}; | ||
const CODE: &str = "event-client"; | ||
#[instrument(name = "event-client-init")] | ||
pub async fn init() -> TardisResult<()> { | ||
let funs = TardisFuns::inst(CODE, None); | ||
let config = funs.conf::<EventClientConfig>(); | ||
let invoke_config = &config.invoke; | ||
invoke_initializer::init(funs.module_code(), invoke_config.clone())?; | ||
|
||
if config.enable { | ||
tracing::info!(?config, "initialize event client"); | ||
let context = TardisContext { | ||
ak: invoke_config.spi_app_id.to_string(), | ||
own_paths: invoke_config.spi_app_id.to_string(), | ||
..Default::default() | ||
}; | ||
init_client_node(config.max_retry_times, Duration::from_millis(config.retry_duration_ms as u64), &context, &funs).await; | ||
} else { | ||
tardis::tracing::info!("event client no enabled"); | ||
} | ||
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,2 @@ | ||
pub mod event_client_config; | ||
pub mod event_client_initializer; |
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 @@ | ||
bios-event |
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