forked from github-starred/komodo
implement correct busy logic
This commit is contained in:
@@ -128,18 +128,32 @@ impl State {
|
||||
|
||||
pub async fn update_build(
|
||||
&self,
|
||||
mut new_build: Build,
|
||||
new_build: Build,
|
||||
user: &RequestUser,
|
||||
) -> anyhow::Result<Build> {
|
||||
if self.build_busy(&new_build.id) {
|
||||
return Err(anyhow!("build busy"))
|
||||
}
|
||||
let id = new_build.id.clone();
|
||||
{
|
||||
let mut lock = self.build_action_states.lock().unwrap();
|
||||
let entry = lock.entry(new_build.id.clone()).or_default();
|
||||
let entry = lock.entry(id.clone()).or_default();
|
||||
entry.updating = true;
|
||||
}
|
||||
let res = self.update_build_inner(new_build, user).await;
|
||||
{
|
||||
let mut lock = self.build_action_states.lock().unwrap();
|
||||
let entry = lock.entry(id).or_default();
|
||||
entry.updating = false;
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
async fn update_build_inner(
|
||||
&self,
|
||||
mut new_build: Build,
|
||||
user: &RequestUser,
|
||||
) -> anyhow::Result<Build> {
|
||||
let current_build = self
|
||||
.get_build_check_permissions(&new_build.id, user, PermissionLevel::Update)
|
||||
.await?;
|
||||
@@ -196,12 +210,6 @@ impl State {
|
||||
|
||||
self.update_update(update).await?;
|
||||
|
||||
{
|
||||
let mut lock = self.build_action_states.lock().unwrap();
|
||||
let entry = lock.entry(new_build.id.clone()).or_default();
|
||||
entry.updating = false;
|
||||
}
|
||||
|
||||
Ok(new_build)
|
||||
}
|
||||
|
||||
@@ -214,7 +222,16 @@ impl State {
|
||||
let entry = lock.entry(build_id.to_string()).or_default();
|
||||
entry.building = true;
|
||||
}
|
||||
let res = self.build_inner(build_id, user).await;
|
||||
{
|
||||
let mut lock = self.build_action_states.lock().unwrap();
|
||||
let entry = lock.entry(build_id.to_string()).or_default();
|
||||
entry.building = false;
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
async fn build_inner(&self, build_id: &str, user: &RequestUser) -> anyhow::Result<Update> {
|
||||
let mut build = self
|
||||
.get_build_check_permissions(build_id, user, PermissionLevel::Update)
|
||||
.await?;
|
||||
@@ -268,20 +285,10 @@ impl State {
|
||||
update.end_ts = Some(monitor_timestamp());
|
||||
self.update_update(update.clone()).await?;
|
||||
|
||||
{
|
||||
let mut lock = self.build_action_states.lock().unwrap();
|
||||
let entry = lock.entry(build_id.to_string()).or_default();
|
||||
entry.building = false;
|
||||
}
|
||||
|
||||
Ok(update)
|
||||
}
|
||||
|
||||
pub async fn reclone_build(
|
||||
&self,
|
||||
build_id: &str,
|
||||
user: &RequestUser,
|
||||
) -> anyhow::Result<Update> {
|
||||
pub async fn reclone_build(&self, build_id: &str, user: &RequestUser) -> anyhow::Result<Update> {
|
||||
if self.build_busy(build_id) {
|
||||
return Err(anyhow!("build busy"))
|
||||
}
|
||||
@@ -290,6 +297,20 @@ impl State {
|
||||
let entry = lock.entry(build_id.to_string()).or_default();
|
||||
entry.recloning = true;
|
||||
}
|
||||
let res = self.reclone_build_inner(build_id, user).await;
|
||||
{
|
||||
let mut lock = self.build_action_states.lock().unwrap();
|
||||
let entry = lock.entry(build_id.to_string()).or_default();
|
||||
entry.recloning = false;
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
async fn reclone_build_inner(
|
||||
&self,
|
||||
build_id: &str,
|
||||
user: &RequestUser,
|
||||
) -> anyhow::Result<Update> {
|
||||
let build = self
|
||||
.get_build_check_permissions(build_id, user, PermissionLevel::Update)
|
||||
.await?;
|
||||
@@ -323,12 +344,6 @@ impl State {
|
||||
|
||||
self.update_update(update.clone()).await?;
|
||||
|
||||
{
|
||||
let mut lock = self.build_action_states.lock().unwrap();
|
||||
let entry = lock.entry(build_id.to_string()).or_default();
|
||||
entry.recloning = false;
|
||||
}
|
||||
|
||||
Ok(update)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,17 +139,32 @@ impl State {
|
||||
|
||||
pub async fn update_deployment(
|
||||
&self,
|
||||
mut new_deployment: Deployment,
|
||||
new_deployment: Deployment,
|
||||
user: &RequestUser,
|
||||
) -> anyhow::Result<Deployment> {
|
||||
if self.deployment_busy(&new_deployment.id) {
|
||||
return Err(anyhow!("deployment busy"))
|
||||
}
|
||||
let id = new_deployment.id.clone();
|
||||
{
|
||||
let mut lock = self.deployment_action_states.lock().unwrap();
|
||||
let entry = lock.entry(new_deployment.id.clone()).or_default();
|
||||
let entry = lock.entry(id.clone()).or_default();
|
||||
entry.updating = true;
|
||||
}
|
||||
let res = self.update_deployment_inner(new_deployment, user).await;
|
||||
{
|
||||
let mut lock = self.deployment_action_states.lock().unwrap();
|
||||
let entry = lock.entry(id).or_default();
|
||||
entry.updating = false;
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
async fn update_deployment_inner(
|
||||
&self,
|
||||
mut new_deployment: Deployment,
|
||||
user: &RequestUser,
|
||||
) -> anyhow::Result<Deployment> {
|
||||
let current_deployment = self
|
||||
.get_deployment_check_permissions(&new_deployment.id, user, PermissionLevel::Update)
|
||||
.await?;
|
||||
@@ -209,12 +224,6 @@ impl State {
|
||||
|
||||
self.update_update(update).await?;
|
||||
|
||||
{
|
||||
let mut lock = self.deployment_action_states.lock().unwrap();
|
||||
let entry = lock.entry(new_deployment.id.clone()).or_default();
|
||||
entry.updating = false;
|
||||
}
|
||||
|
||||
Ok(new_deployment)
|
||||
}
|
||||
|
||||
@@ -231,6 +240,20 @@ impl State {
|
||||
let entry = lock.entry(deployment_id.to_string()).or_default();
|
||||
entry.recloning = true;
|
||||
}
|
||||
let res = self.reclone_deployment_inner(deployment_id, user).await;
|
||||
{
|
||||
let mut lock = self.deployment_action_states.lock().unwrap();
|
||||
let entry = lock.entry(deployment_id.to_string()).or_default();
|
||||
entry.recloning = false;
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
async fn reclone_deployment_inner(
|
||||
&self,
|
||||
deployment_id: &str,
|
||||
user: &RequestUser,
|
||||
) -> anyhow::Result<Update> {
|
||||
let deployment = self
|
||||
.get_deployment_check_permissions(deployment_id, user, PermissionLevel::Execute)
|
||||
.await?;
|
||||
@@ -264,12 +287,6 @@ impl State {
|
||||
|
||||
self.update_update(update.clone()).await?;
|
||||
|
||||
{
|
||||
let mut lock = self.deployment_action_states.lock().unwrap();
|
||||
let entry = lock.entry(deployment_id.to_string()).or_default();
|
||||
entry.recloning = false;
|
||||
}
|
||||
|
||||
Ok(update)
|
||||
}
|
||||
|
||||
@@ -286,6 +303,20 @@ impl State {
|
||||
let entry = lock.entry(deployment_id.to_string()).or_default();
|
||||
entry.deploying = true;
|
||||
}
|
||||
let res = self.deploy_container_inner(deployment_id, user).await;
|
||||
{
|
||||
let mut lock = self.deployment_action_states.lock().unwrap();
|
||||
let entry = lock.entry(deployment_id.to_string()).or_default();
|
||||
entry.deploying = false;
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
async fn deploy_container_inner(
|
||||
&self,
|
||||
deployment_id: &str,
|
||||
user: &RequestUser,
|
||||
) -> anyhow::Result<Update> {
|
||||
let mut deployment = self
|
||||
.get_deployment_check_permissions(deployment_id, user, PermissionLevel::Execute)
|
||||
.await?;
|
||||
@@ -328,12 +359,6 @@ impl State {
|
||||
|
||||
self.update_update(update.clone()).await?;
|
||||
|
||||
{
|
||||
let mut lock = self.deployment_action_states.lock().unwrap();
|
||||
let entry = lock.entry(deployment_id.to_string()).or_default();
|
||||
entry.deploying = false;
|
||||
}
|
||||
|
||||
Ok(update)
|
||||
}
|
||||
|
||||
@@ -350,6 +375,20 @@ impl State {
|
||||
let entry = lock.entry(deployment_id.to_string()).or_default();
|
||||
entry.starting = true;
|
||||
}
|
||||
let res = self.start_container_inner(deployment_id, user).await;
|
||||
{
|
||||
let mut lock = self.deployment_action_states.lock().unwrap();
|
||||
let entry = lock.entry(deployment_id.to_string()).or_default();
|
||||
entry.starting = false;
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
async fn start_container_inner(
|
||||
&self,
|
||||
deployment_id: &str,
|
||||
user: &RequestUser,
|
||||
) -> anyhow::Result<Update> {
|
||||
let start_ts = monitor_timestamp();
|
||||
let deployment = self
|
||||
.get_deployment_check_permissions(deployment_id, user, PermissionLevel::Execute)
|
||||
@@ -390,12 +429,6 @@ impl State {
|
||||
|
||||
self.update_update(update.clone()).await?;
|
||||
|
||||
{
|
||||
let mut lock = self.deployment_action_states.lock().unwrap();
|
||||
let entry = lock.entry(deployment_id.to_string()).or_default();
|
||||
entry.starting = false;
|
||||
}
|
||||
|
||||
Ok(update)
|
||||
}
|
||||
|
||||
@@ -412,6 +445,20 @@ impl State {
|
||||
let entry = lock.entry(deployment_id.to_string()).or_default();
|
||||
entry.stopping = true;
|
||||
}
|
||||
let res = self.stop_container_inner(deployment_id, user).await;
|
||||
{
|
||||
let mut lock = self.deployment_action_states.lock().unwrap();
|
||||
let entry = lock.entry(deployment_id.to_string()).or_default();
|
||||
entry.stopping = false;
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
async fn stop_container_inner(
|
||||
&self,
|
||||
deployment_id: &str,
|
||||
user: &RequestUser,
|
||||
) -> anyhow::Result<Update> {
|
||||
let start_ts = monitor_timestamp();
|
||||
let deployment = self
|
||||
.get_deployment_check_permissions(deployment_id, user, PermissionLevel::Execute)
|
||||
@@ -452,12 +499,6 @@ impl State {
|
||||
|
||||
self.update_update(update.clone()).await?;
|
||||
|
||||
{
|
||||
let mut lock = self.deployment_action_states.lock().unwrap();
|
||||
let entry = lock.entry(deployment_id.to_string()).or_default();
|
||||
entry.stopping = false;
|
||||
}
|
||||
|
||||
Ok(update)
|
||||
}
|
||||
|
||||
@@ -474,6 +515,20 @@ impl State {
|
||||
let entry = lock.entry(deployment_id.to_string()).or_default();
|
||||
entry.removing = true;
|
||||
}
|
||||
let res = self.remove_container_inner(deployment_id, user).await;
|
||||
{
|
||||
let mut lock = self.deployment_action_states.lock().unwrap();
|
||||
let entry = lock.entry(deployment_id.to_string()).or_default();
|
||||
entry.removing = false;
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
async fn remove_container_inner(
|
||||
&self,
|
||||
deployment_id: &str,
|
||||
user: &RequestUser,
|
||||
) -> anyhow::Result<Update> {
|
||||
let start_ts = monitor_timestamp();
|
||||
let deployment = self
|
||||
.get_deployment_check_permissions(deployment_id, user, PermissionLevel::Execute)
|
||||
@@ -514,12 +569,6 @@ impl State {
|
||||
|
||||
self.update_update(update.clone()).await?;
|
||||
|
||||
{
|
||||
let mut lock = self.deployment_action_states.lock().unwrap();
|
||||
let entry = lock.entry(deployment_id.to_string()).or_default();
|
||||
entry.removing = false;
|
||||
}
|
||||
|
||||
Ok(update)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,6 +177,20 @@ impl State {
|
||||
let entry = lock.entry(server_id.to_string()).or_default();
|
||||
entry.pruning_networks = true;
|
||||
}
|
||||
let res = self.prune_networks_inner(server_id, user).await;
|
||||
{
|
||||
let mut lock = self.server_action_states.lock().unwrap();
|
||||
let entry = lock.entry(server_id.to_string()).or_default();
|
||||
entry.pruning_networks = false;
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
async fn prune_networks_inner(
|
||||
&self,
|
||||
server_id: &str,
|
||||
user: &RequestUser,
|
||||
) -> anyhow::Result<Update> {
|
||||
let server = self
|
||||
.get_server_check_permissions(server_id, user, PermissionLevel::Execute)
|
||||
.await?;
|
||||
@@ -208,12 +222,6 @@ impl State {
|
||||
|
||||
self.update_update(update.clone()).await?;
|
||||
|
||||
{
|
||||
let mut lock = self.server_action_states.lock().unwrap();
|
||||
let entry = lock.entry(server_id.to_string()).or_default();
|
||||
entry.pruning_networks = false;
|
||||
}
|
||||
|
||||
Ok(update)
|
||||
}
|
||||
|
||||
@@ -230,6 +238,20 @@ impl State {
|
||||
let entry = lock.entry(server_id.to_string()).or_default();
|
||||
entry.pruning_images = true;
|
||||
}
|
||||
let res = self.prune_images_inner(server_id, user).await;
|
||||
{
|
||||
let mut lock = self.server_action_states.lock().unwrap();
|
||||
let entry = lock.entry(server_id.to_string()).or_default();
|
||||
entry.pruning_images = false;
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
async fn prune_images_inner(
|
||||
&self,
|
||||
server_id: &str,
|
||||
user: &RequestUser,
|
||||
) -> anyhow::Result<Update> {
|
||||
let server = self
|
||||
.get_server_check_permissions(server_id, user, PermissionLevel::Execute)
|
||||
.await?;
|
||||
@@ -262,12 +284,6 @@ impl State {
|
||||
|
||||
self.update_update(update.clone()).await?;
|
||||
|
||||
{
|
||||
let mut lock = self.server_action_states.lock().unwrap();
|
||||
let entry = lock.entry(server_id.to_string()).or_default();
|
||||
entry.pruning_images = false;
|
||||
}
|
||||
|
||||
Ok(update)
|
||||
}
|
||||
|
||||
@@ -284,6 +300,20 @@ impl State {
|
||||
let entry = lock.entry(server_id.to_string()).or_default();
|
||||
entry.pruning_containers = true;
|
||||
}
|
||||
let res = self.prune_containers_inner(server_id, user).await;
|
||||
{
|
||||
let mut lock = self.server_action_states.lock().unwrap();
|
||||
let entry = lock.entry(server_id.to_string()).or_default();
|
||||
entry.pruning_containers = false;
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
async fn prune_containers_inner(
|
||||
&self,
|
||||
server_id: &str,
|
||||
user: &RequestUser,
|
||||
) -> anyhow::Result<Update> {
|
||||
let server = self
|
||||
.get_server_check_permissions(server_id, user, PermissionLevel::Execute)
|
||||
.await?;
|
||||
@@ -319,12 +349,6 @@ impl State {
|
||||
|
||||
self.update_update(update.clone()).await?;
|
||||
|
||||
{
|
||||
let mut lock = self.server_action_states.lock().unwrap();
|
||||
let entry = lock.entry(server_id.to_string()).or_default();
|
||||
entry.pruning_containers = false;
|
||||
}
|
||||
|
||||
Ok(update)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user