waveless_runtime/services/http_facade/
handler.rs1use waveless_commons::databases::DatabaseConsumer;
5
6use crate::*;
7
8#[derive(Clone, Debug)]
10pub struct ExecuteHandler;
11
12impl Service<RequestCx> for ExecuteHandler {
13 type Response = ResponseCx;
14
15 type Error = RequestError;
16
17 type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
18
19 fn poll_ready(&mut self, _cx: &mut std::task::Context<'_>) -> Poll<Result<(), Self::Error>> {
20 Poll::Ready(Ok(()))
21 }
22
23 fn call(&mut self, cx: RequestCx) -> Self::Future {
25 let future: Pin<_> = Box::pin(async move {
26 let RequestCx { endpoint, .. } = &cx;
27
28 let db_conns = endpoint.get_db_handle()?;
30
31 let ExecutionTarget::Http(http_target) = endpoint.execution_target().to_owned() else {
33 unreachable!()
34 };
35
36 let Some(execution_atom) = http_target.execution_pipeline() else {
37 return Err(RequestError::Expected(
38 StatusCode::INTERNAL_SERVER_ERROR,
39 format!("The route doesn't have any executor defined. HINT: Go to your project's endpoints folder and check that '{}' has an executor set.", endpoint.id()).into(),
40 ));
41 };
42
43 let mut pipeline_cx = PipelineCx::new(cx);
45
46 pipeline_cx = execution_atom.execute(pipeline_cx, db_conns).await?;
48
49 let PipelineCx { response, .. } = pipeline_cx;
50
51 Ok(response.unwrap_or_default())
52 }).into();
53
54 future as Self::Future }
56}