v1: initialize
- git repo fetcher service, compatible with registry tbm Signed-off-by: Pakin <pakin.t@forth.co.th>
This commit is contained in:
commit
7f8b19353a
9 changed files with 3823 additions and 0 deletions
39
src/reg.rs
Normal file
39
src/reg.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use tokio::time::sleep;
|
||||
use tonic::transport::Channel;
|
||||
|
||||
use crate::reg::registry::{ServiceHeartbeat, ServiceInfo, registry_client::RegistryClient};
|
||||
|
||||
pub mod registry {
|
||||
tonic::include_proto!("registry");
|
||||
}
|
||||
|
||||
pub async fn register_service(client: &mut RegistryClient<Channel>, name: &str, url: &str) {
|
||||
let req = tonic::Request::new(ServiceInfo {
|
||||
name: name.to_string(),
|
||||
url: url.to_string(),
|
||||
healthz: "/healthz".to_string(),
|
||||
token: std::env::var("REGISTRY_TOKEN").unwrap_or_default(),
|
||||
});
|
||||
|
||||
let _ = client.register(req).await;
|
||||
}
|
||||
|
||||
pub async fn heartbeat_loop(name: String, url: String) {
|
||||
loop {
|
||||
// TODO: adjust connection path
|
||||
if let Ok(mut client) = RegistryClient::connect("http://localhost:50051").await {
|
||||
let req = tonic::Request::new(ServiceHeartbeat {
|
||||
name: name.clone(),
|
||||
url: url.clone(),
|
||||
});
|
||||
let _ = client.heartbeat(req).await;
|
||||
}
|
||||
sleep(Duration::from_secs(10)).await;
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn health() -> &'static str {
|
||||
"git-fetch-service.rs ok"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue