diff --git a/examples/kubernetes_example/src/main.rs b/examples/kubernetes_example/src/main.rs index 8deb4572..8ebbef1b 100644 --- a/examples/kubernetes_example/src/main.rs +++ b/examples/kubernetes_example/src/main.rs @@ -1,3 +1,4 @@ +#![feature(async_closure)] // not actually necessary, just added to test that feature defs work. #[macro_use] extern crate lazy_static; #[macro_use(c)] diff --git a/examples/local_queue_example/src/main.rs b/examples/local_queue_example/src/main.rs index 6b09adc9..b305d888 100644 --- a/examples/local_queue_example/src/main.rs +++ b/examples/local_queue_example/src/main.rs @@ -1,3 +1,4 @@ +#![feature(async_closure)] // not actually necessary, just added to test that feature defs work. extern crate proc_macro; use futures::future::try_join_all; use rand; diff --git a/turbolift_macros/src/lib.rs b/turbolift_macros/src/lib.rs index a097319b..b2436768 100644 --- a/turbolift_macros/src/lib.rs +++ b/turbolift_macros/src/lib.rs @@ -74,59 +74,54 @@ pub fn on(distribution_platform_: TokenStream, function_: TokenStream) -> TokenS let sanitized_file = extract_function::get_sanitized_file(&function); // todo make code below hygienic in case sanitized_file also imports from actix_web let main_file = q! { - use turbolift::actix_web::{self, get, web, HttpResponse, HttpRequest, Result, Responder}; + #sanitized_file use turbolift::tokio_compat_02::FutureExt; - #sanitized_file #dummy_function #target_function - #[get("/health-probe")] - async fn health_probe(_req: HttpRequest) -> impl Responder { - HttpResponse::Ok() + async fn health_probe(_req: turbolift::actix_web::HttpRequest) -> impl turbolift::actix_web::Responder { + turbolift::actix_web::HttpResponse::Ok() } - #[get(#wrapper_route)] #[turbolift::tracing::instrument] - async fn turbolift_wrapper(web::Path((#untyped_params_tokens_with_run_id)): web::Path<(#param_types)>) -> Result { - Ok( - HttpResponse::Ok() - .json(#function_name(#untyped_params_tokens)) - ) + async fn turbolift_wrapper(turbolift::actix_web::web::Path((#untyped_params_tokens_with_run_id)): turbolift::actix_web::web::Path<(#param_types)>) -> impl turbolift::actix_web::Responder { + turbolift::actix_web::HttpResponse::Ok() + .json(#function_name(#untyped_params_tokens)) } - #[actix_web::main] #[turbolift::tracing::instrument] - async fn main() -> std::io::Result<()> { - use actix_web::{App, HttpServer, HttpRequest, web}; - - let args: Vec = std::env::args().collect(); - let ip_and_port = &args[1]; - turbolift::tracing::info!("service main() started. ip_and_port parsed."); - HttpServer::new( - || - App::new() - .service( - turbolift_wrapper - ) - .service( - health_probe - ) - .default_service( - web::get() - .to( - |req: HttpRequest| - HttpResponse::NotFound().body( - format!("endpoint not found: {}", req.uri()) + fn main() { + turbolift::actix_web::rt::System::new("main".to_string()) + .block_on(async move { + let args: Vec = std::env::args().collect(); + let ip_and_port = &args[1]; + turbolift::tracing::info!("service main() started. ip_and_port parsed."); + turbolift::actix_web::HttpServer::new( + || + turbolift::actix_web::App::new() + .route( + #wrapper_route, turbolift::actix_web::web::get().to(turbolift_wrapper) + ) + .route( + "/health-probe", turbolift::actix_web::web::get().to(health_probe) + ) + .default_service( + turbolift::actix_web::web::get() + .to( + |req: turbolift::actix_web::HttpRequest| + turbolift::actix_web::HttpResponse::NotFound().body( + format!("endpoint not found: {}", req.uri()) + ) ) ) - ) - ) - .bind(ip_and_port)? - .run() - .compat() - .await - } + ) + .bind(ip_and_port)? + .run() + .compat() + .await + }).unwrap(); + } }; // copy all files in repo into cache