feat: handle errors in deploy endpoint

fix-update-website
Aravinth Manivannan 7 months ago
parent 4b43c4ed3d
commit eb87453bd1
Signed by: realaravinth
GPG Key ID: AD9F0F08E855ED88
  1. 1
      Cargo.lock
  2. 2
      Cargo.toml
  3. 17
      src/deploy.rs

1
Cargo.lock generated

@ -997,6 +997,7 @@ dependencies = [
"pretty_env_logger",
"serde",
"serde_json",
"tokio",
"url",
]

@ -35,5 +35,7 @@ derive_more = "0.99"
num_cpus = "1.13"
tokio = { version = "1", features=["sync"]}
[dev-dependencies]
mktemp = "0.4.1"

@ -16,7 +16,9 @@
*/
use actix_web::{web, HttpResponse, Responder};
use serde::{Deserialize, Serialize};
use tokio::sync::oneshot;
use crate::errors::*;
use crate::SETTINGS;
pub mod routes {
@ -40,24 +42,21 @@ pub struct DeployEvent {
}
#[my_codegen::post(path = "crate::V1_API_ROUTES.deploy.update")]
async fn update(payload: web::Json<DeployEvent>) -> impl Responder {
let mut found = false;
async fn update(payload: web::Json<DeployEvent>) -> ServiceResult<impl Responder> {
for page in SETTINGS.pages.iter() {
if page.secret == payload.secret {
let (tx, rx) = oneshot::channel();
web::block(|| {
page.update();
tx.send(page.update()).unwrap();
})
.await
.unwrap();
found = true;
rx.await.unwrap()?;
return Ok(HttpResponse::Ok());
}
}
if found {
HttpResponse::Ok()
} else {
HttpResponse::NotFound()
}
Err(ServiceError::WebsiteNotFound)
}
pub fn services(cfg: &mut web::ServiceConfig) {

Loading…
Cancel
Save