features: app engine #1
@ -94,7 +94,7 @@ impl NewAppReq {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct AppNodeWithReports {
|
||||
pub id: RecordId,
|
||||
pub operator: RecordId,
|
||||
@ -116,6 +116,7 @@ impl AppNodeWithReports {
|
||||
pub async fn find_by_filters(
|
||||
db: &Surreal<Client>,
|
||||
filters: app_proto::AppNodeFilters,
|
||||
limit_one: bool,
|
||||
) -> Result<Vec<Self>, Error> {
|
||||
let mut filter_query = format!(
|
||||
"select *, <-report.* from {APP_NODE} where
|
||||
@ -123,7 +124,7 @@ impl AppNodeWithReports {
|
||||
max_ports_per_app >= {} &&
|
||||
avail_vcpus >= {} &&
|
||||
avail_mem_mb >= {} &&
|
||||
avail_storage_gbs >= {}\n",
|
||||
avail_storage_gbs >= {} ",
|
||||
filters.free_ports,
|
||||
filters.free_ports,
|
||||
filters.vcpus,
|
||||
@ -143,8 +144,12 @@ impl AppNodeWithReports {
|
||||
if !filters.ip.is_empty() {
|
||||
filter_query += &format!("&& ip = '{}' ", filters.ip);
|
||||
}
|
||||
|
||||
if limit_one {
|
||||
filter_query += "limit 1";
|
||||
}
|
||||
|
||||
filter_query += ";";
|
||||
dbg!(&filter_query);
|
||||
let mut query_resp = db.query(filter_query).await?;
|
||||
let app_nodes: Vec<Self> = query_resp.take(0)?;
|
||||
Ok(app_nodes)
|
||||
|
@ -113,7 +113,7 @@ pub struct Kick {
|
||||
contract: RecordId,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Report {
|
||||
#[serde(rename = "in")]
|
||||
from_account: RecordId,
|
||||
|
@ -219,7 +219,7 @@ impl BrainAppCli for AppCliServer {
|
||||
) -> Result<tonic::Response<<Self as BrainAppCli>::ListAppNodesStream>, tonic::Status> {
|
||||
let req = check_sig_from_req(req)?;
|
||||
info!("list_app_nodes process starting for {:?}", req);
|
||||
let app_nodes = db::AppNodeWithReports::find_by_filters(&self.db, req).await?;
|
||||
let app_nodes = db::AppNodeWithReports::find_by_filters(&self.db, req, false).await?;
|
||||
let (tx, rx) = mpsc::channel(6);
|
||||
tokio::spawn(async move {
|
||||
for app_node in app_nodes {
|
||||
@ -236,7 +236,12 @@ impl BrainAppCli for AppCliServer {
|
||||
) -> Result<tonic::Response<AppNodeListResp>, tonic::Status> {
|
||||
let req = check_sig_from_req(req)?;
|
||||
info!("get_one_app_node process starting for {:?}", req);
|
||||
let app_node = db::AppNodeWithReports::find_by_filters(&self.db, req, true)
|
||||
.await?
|
||||
.first()
|
||||
.ok_or(Status::not_found("No app node found"))?
|
||||
.clone();
|
||||
|
||||
todo!()
|
||||
Ok(Response::new(app_node.into()))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user