Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: revive via gateway endpoint #460

Merged
merged 4 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat: send task to global queue
  • Loading branch information
oddgrd committed Nov 4, 2022
commit 4dd08c915fbeca204a66179993afce488b9345ad
5 changes: 3 additions & 2 deletions gateway/src/api/latest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use axum::body::{Body, BoxBody};
use axum::extract::{Extension, Path};
use axum::http::Request;
use axum::response::Response;
use axum::routing::{any, get};
use axum::routing::{any, get, post};
use axum::{Json as AxumJson, Router};
use http::StatusCode;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -157,8 +157,9 @@ async fn get_status(Extension(sender): Extension<Sender<BoxedTask>>) -> Response
async fn revive_projects(
brokad marked this conversation as resolved.
Show resolved Hide resolved
_: Admin,
Extension(service): Extension<Arc<GatewayService>>,
Extension(sender): Extension<Sender<BoxedTask>>,
) -> Result<(), Error> {
crate::project::exec::revive(service)
crate::project::exec::revive(service, sender)
.await
.map_err(|_| Error::from_kind(ErrorKind::Internal))
}
Expand Down
39 changes: 18 additions & 21 deletions gateway/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,20 +838,23 @@ where
}

pub mod exec {

use std::sync::Arc;

use bollard::service::ContainerState;
use tokio::sync::mpsc::Sender;

use crate::{
service::GatewayService,
task::{self, TaskResult},
task::{self, BoxedTask, TaskResult},
};

use super::*;

pub async fn revive(gateway: Arc<GatewayService>) -> Result<(), ProjectError> {
let mut mutations = Vec::new();

pub async fn revive(
gateway: Arc<GatewayService>,
sender: Sender<BoxedTask>,
) -> Result<(), ProjectError> {
for (project_name, account_name) in gateway
.iter_projects()
.await
Expand All @@ -872,30 +875,24 @@ pub mod exec {
..
}) = container.state
{
mutations.push((
project_name.clone(),
gateway
.new_task()
.project(project_name)
.account(account_name)
.and_then(task::run(|ctx| async move {
TaskResult::Done(Project::Stopped(ProjectStopped {
container: ctx.state.container().unwrap(),
}))
debug!("{} will be revived", project_name.clone());
_ = gateway
.new_task()
.project(project_name)
.account(account_name)
.and_then(task::run(|ctx| async move {
TaskResult::Done(Project::Stopped(ProjectStopped {
container: ctx.state.container().unwrap(),
}))
.build(),
));
}))
.send(&sender)
.await;
}
}
}
}
}

for (project_name, mut work) in mutations {
debug!(?project_name, "project will be revived");
while let TaskResult::Pending(_) = work.poll(()).await {}
}

Ok(())
}
}
Expand Down