switch to managers: wip

This commit is contained in:
Aiden McClelland
2021-07-13 16:55:05 -06:00
committed by Aiden McClelland
parent e2b77b23f8
commit 34e4c12af3
26 changed files with 783 additions and 803 deletions

View File

@@ -6,7 +6,6 @@ use serde::{Deserialize, Deserializer, Serialize};
use crate::action::ActionImplementation;
use crate::id::Id;
use crate::net::host::Hosts;
use crate::s9pk::manifest::PackageId;
use crate::util::Version;
use crate::volume::Volumes;
@@ -51,13 +50,12 @@ impl HealthChecks {
pkg_id: &PackageId,
pkg_version: &Version,
volumes: &Volumes,
hosts: &Hosts,
) -> Result<IndexMap<HealthCheckId, HealthCheckResult>, Error> {
let res = futures::future::try_join_all(self.0.iter().map(|(id, check)| async move {
Ok::<_, Error>((
id.clone(),
check
.check(started, pkg_id, pkg_version, volumes, hosts)
.check(id, started, pkg_id, pkg_version, volumes)
.await?,
))
}))
@@ -75,15 +73,22 @@ pub struct HealthCheck {
impl HealthCheck {
pub async fn check(
&self,
id: &HealthCheckId,
started: &DateTime<Utc>,
pkg_id: &PackageId,
pkg_version: &Version,
volumes: &Volumes,
hosts: &Hosts,
) -> Result<HealthCheckResult, Error> {
let res = self
.implementation
.execute(pkg_id, pkg_version, volumes, hosts, Some(started), true)
.execute(
pkg_id,
pkg_version,
Some(&format!("{}Health", id)),
volumes,
Some(started),
true,
)
.await?;
Ok(HealthCheckResult {
time: Utc::now(),

View File

@@ -18,7 +18,6 @@ use crate::db::model::{
CurrentDependencyInfo, InstalledPackageDataEntryModel, PackageDataEntryModel,
};
use crate::dependencies::{Dependencies, DependencyError};
use crate::net::host::Hosts;
use crate::net::interface::InterfaceId;
use crate::s9pk::manifest::{Manifest, PackageId};
use crate::status::health_check::HealthCheckResultVariant;
@@ -46,7 +45,7 @@ pub async fn synchronize_all(ctx: &RpcContext) -> Result<(), Error> {
.get(&mut db)
.await?
{
container_names.push(DockerAction::container_name(id.as_ref(), version));
container_names.push(DockerAction::container_name(id.as_ref(), None));
} else {
pkg_ids.remove(&id);
}
@@ -168,12 +167,11 @@ pub async fn check_all(ctx: &RpcContext) -> Result<(), Error> {
async fn main_status<Db: DbHandle>(
status_model: StatusModel,
manifest: Arc<ModelData<Manifest>>,
hosts: Arc<Hosts>,
mut db: Db,
) -> Result<MainStatus, Error> {
let mut status = status_model.get_mut(&mut db).await?;
status.main.check(&*manifest, &*hosts).await?;
status.main.check(&*manifest).await?;
let res = status.main.clone();
@@ -192,7 +190,7 @@ pub async fn check_all(ctx: &RpcContext) -> Result<(), Error> {
.for_each_concurrent(None, move |(((status, manifest), id), hosts)| {
let status_sender = status_sender.clone();
async move {
match tokio::spawn(main_status(status, manifest, hosts, ctx.db.handle()))
match tokio::spawn(main_status(status, manifest, ctx.db.handle()))
.await
.unwrap()
{
@@ -292,7 +290,7 @@ impl MainStatus {
.and_then(|s| s.status)
== Some(ContainerStateStatusEnum::RUNNING))
}
let name = DockerAction::container_name(&manifest.id, &manifest.version);
let name = DockerAction::container_name(&manifest.id, None);
let state = summary.state.as_ref().map(|s| s.as_str());
match state {
Some("created") | Some("exited") => match self {
@@ -343,18 +341,12 @@ impl MainStatus {
}
Ok(false)
}
pub async fn check(&mut self, manifest: &Manifest, hosts: &Hosts) -> Result<(), Error> {
pub async fn check(&mut self, manifest: &Manifest) -> Result<(), Error> {
match self {
MainStatus::Running { started, health } => {
*health = manifest
.health_checks
.check_all(
started,
&manifest.id,
&manifest.version,
&manifest.volumes,
hosts,
)
.check_all(started, &manifest.id, &manifest.version, &manifest.volumes)
.await?;
for (check, res) in health {
if matches!(