Kaynağa Gözat

disable agenda (#2)

LoGin 1 yıl önce
ebeveyn
işleme
d72160e3d0
1 değiştirilmiş dosya ile 51 ekleme ve 50 silme
  1. 51 50
      src/main.rs

+ 51 - 50
src/main.rs

@@ -7,7 +7,7 @@ use hyper::{header, Body, Request, Response, Server, StatusCode};
 use route_recognizer::Router;
 use std::{env, net::SocketAddr, sync::Arc};
 use tokio::{task, time};
-use tower::{Service, ServiceExt};
+// use tower::{Service, ServiceExt};
 use tracing as log;
 use tracing::Instrument;
 use triagebot::handlers::pull_requests_assignment_update::PullRequestAssignmentUpdate;
@@ -16,6 +16,7 @@ use triagebot::jobs::{
 };
 use triagebot::{db, github, handlers::Context, notification_listing, payload, EventName};
 
+#[allow(dead_code)]
 async fn handle_agenda_request(req: String) -> anyhow::Result<String> {
     if req == "/agenda/lang/triage" {
         return triagebot::agenda::lang().call().await;
@@ -33,7 +34,7 @@ async fn handle_agenda_request(req: String) -> anyhow::Result<String> {
 async fn serve_req(
     req: Request<Body>,
     ctx: Arc<Context>,
-    mut agenda: impl Service<String, Response = String, Error = tower::BoxError>,
+    // mut agenda: impl Service<String, Response = String, Error = tower::BoxError>,
 ) -> Result<Response<Body>, hyper::Error> {
     log::info!("request = {:?}", req);
     let mut router = Router::new();
@@ -52,37 +53,37 @@ async fn serve_req(
         }
     }
 
-    if req.uri.path() == "/agenda" {
-        return Ok(Response::builder()
-            .status(StatusCode::OK)
-            .body(Body::from(triagebot::agenda::INDEX))
-            .unwrap());
-    }
-    if req.uri.path() == "/agenda/lang/triage"
-        || req.uri.path() == "/agenda/lang/planning"
-        || req.uri.path() == "/agenda/types/planning"
-    {
-        match agenda
-            .ready()
-            .await
-            .expect("agenda keeps running")
-            .call(req.uri.path().to_owned())
-            .await
-        {
-            Ok(agenda) => {
-                return Ok(Response::builder()
-                    .status(StatusCode::OK)
-                    .body(Body::from(agenda))
-                    .unwrap())
-            }
-            Err(err) => {
-                return Ok(Response::builder()
-                    .status(StatusCode::INTERNAL_SERVER_ERROR)
-                    .body(Body::from(err.to_string()))
-                    .unwrap())
-            }
-        }
-    }
+    // if req.uri.path() == "/agenda" {
+    //     return Ok(Response::builder()
+    //         .status(StatusCode::OK)
+    //         .body(Body::from(triagebot::agenda::INDEX))
+    //         .unwrap());
+    // }
+    // if req.uri.path() == "/agenda/lang/triage"
+    //     || req.uri.path() == "/agenda/lang/planning"
+    //     || req.uri.path() == "/agenda/types/planning"
+    // {
+    //     match agenda
+    //         .ready()
+    //         .await
+    //         .expect("agenda keeps running")
+    //         .call(req.uri.path().to_owned())
+    //         .await
+    //     {
+    //         Ok(agenda) => {
+    //             return Ok(Response::builder()
+    //                 .status(StatusCode::OK)
+    //                 .body(Body::from(agenda))
+    //                 .unwrap())
+    //         }
+    //         Err(err) => {
+    //             return Ok(Response::builder()
+    //                 .status(StatusCode::INTERNAL_SERVER_ERROR)
+    //                 .body(Body::from(err.to_string()))
+    //                 .unwrap())
+    //         }
+    //     }
+    // }
 
     if req.uri.path() == "/" {
         return Ok(Response::builder()
@@ -275,30 +276,30 @@ async fn run_server(addr: SocketAddr) -> anyhow::Result<()> {
         spawn_job_runner(ctx.clone());
     }
 
-    let agenda = tower::ServiceBuilder::new()
-        .buffer(10)
-        .layer_fn(|input| {
-            tower::util::MapErr::new(
-                tower::load_shed::LoadShed::new(tower::limit::RateLimit::new(
-                    input,
-                    tower::limit::rate::Rate::new(2, std::time::Duration::from_secs(60)),
-                )),
-                |e| {
-                    tracing::error!("agenda request failed: {:?}", e);
-                    anyhow::anyhow!("Rate limit of 2 request / 60 seconds exceeded")
-                },
-            )
-        })
-        .service_fn(handle_agenda_request);
+    // let agenda = tower::ServiceBuilder::new()
+    //     .buffer(10)
+    //     .layer_fn(|input| {
+    //         tower::util::MapErr::new(
+    //             tower::load_shed::LoadShed::new(tower::limit::RateLimit::new(
+    //                 input,
+    //                 tower::limit::rate::Rate::new(2, std::time::Duration::from_secs(60)),
+    //             )),
+    //             |e| {
+    //                 tracing::error!("agenda request failed: {:?}", e);
+    //                 anyhow::anyhow!("Rate limit of 2 request / 60 seconds exceeded")
+    //             },
+    //         )
+    //     })
+    //     .service_fn(handle_agenda_request);
 
     let svc = hyper::service::make_service_fn(move |_conn| {
         let ctx = ctx.clone();
-        let agenda = agenda.clone();
+        // let agenda = agenda.clone();
         async move {
             Ok::<_, hyper::Error>(hyper::service::service_fn(move |req| {
                 let uuid = uuid::Uuid::new_v4();
                 let span = tracing::span!(tracing::Level::INFO, "request", ?uuid);
-                serve_req(req, ctx.clone(), agenda.clone())
+                serve_req(req, ctx.clone())
                     .map(move |mut resp| {
                         if let Ok(resp) = &mut resp {
                             resp.headers_mut()