forked from github-starred/komodo
get server / deployment status from cache
This commit is contained in:
@@ -61,6 +61,28 @@ impl Resolve<ListDeployments, RequestUser> for State {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Resolve<GetDeploymentStatus, RequestUser> for State {
|
||||
async fn resolve(
|
||||
&self,
|
||||
GetDeploymentStatus { id }: GetDeploymentStatus,
|
||||
user: RequestUser,
|
||||
) -> anyhow::Result<GetDeploymentStatusResponse> {
|
||||
self.get_deployment_check_permissions(&id, &user, PermissionLevel::Read)
|
||||
.await?;
|
||||
let status = self
|
||||
.deployment_status_cache
|
||||
.get(&id)
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
let response = GetDeploymentStatusResponse {
|
||||
status: status.container.as_ref().and_then(|c| c.status.clone()),
|
||||
state: status.state,
|
||||
};
|
||||
Ok(response)
|
||||
}
|
||||
}
|
||||
|
||||
const MAX_LOG_LENGTH: u64 = 5000;
|
||||
|
||||
#[async_trait]
|
||||
|
||||
@@ -71,6 +71,27 @@ impl Resolve<ListServers, RequestUser> for State {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Resolve<GetServerStatus, RequestUser> for State {
|
||||
async fn resolve(
|
||||
&self,
|
||||
GetServerStatus { id }: GetServerStatus,
|
||||
user: RequestUser,
|
||||
) -> anyhow::Result<GetServerStatusResponse> {
|
||||
self.get_server_check_permissions(&id, &user, PermissionLevel::Read)
|
||||
.await?;
|
||||
let status = self
|
||||
.server_status_cache
|
||||
.get(&id)
|
||||
.await
|
||||
.ok_or(anyhow!("did not find cached status for server"))?;
|
||||
let response = GetServerStatusResponse {
|
||||
status: status.status,
|
||||
};
|
||||
Ok(response)
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Resolve<GetServerActionState, RequestUser> for State {
|
||||
async fn resolve(
|
||||
|
||||
@@ -4,7 +4,7 @@ use typeshare::typeshare;
|
||||
|
||||
use crate::{
|
||||
entities::{
|
||||
deployment::{Deployment, DeploymentActionState, DockerContainerStats},
|
||||
deployment::{Deployment, DeploymentActionState, DockerContainerStats, DockerContainerState},
|
||||
update::Log,
|
||||
},
|
||||
MongoDocument,
|
||||
@@ -30,6 +30,22 @@ pub struct ListDeployments {
|
||||
|
||||
//
|
||||
|
||||
#[typeshare]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(GetDeploymentStatusResponse)]
|
||||
pub struct GetDeploymentStatus {
|
||||
pub id: String,
|
||||
}
|
||||
|
||||
#[typeshare]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct GetDeploymentStatusResponse {
|
||||
pub status: Option<String>,
|
||||
pub state: DockerContainerState
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[typeshare]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(Log)]
|
||||
|
||||
@@ -12,7 +12,7 @@ use crate::{
|
||||
AllSystemStats, BasicSystemStats, CpuUsage, DiskUsage, NetworkUsage,
|
||||
SystemComponent, SystemInformation, SystemProcess,
|
||||
},
|
||||
Server, ServerActionState,
|
||||
Server, ServerActionState, ServerStatus,
|
||||
},
|
||||
},
|
||||
MongoDocument,
|
||||
@@ -38,6 +38,21 @@ pub struct ListServers {
|
||||
|
||||
//
|
||||
|
||||
#[typeshare]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(GetServerStatusResponse)]
|
||||
pub struct GetServerStatus {
|
||||
pub id: String,
|
||||
}
|
||||
|
||||
#[typeshare]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct GetServerStatusResponse {
|
||||
pub status: ServerStatus,
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[typeshare]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(ServerActionState)]
|
||||
|
||||
Reference in New Issue
Block a user