Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix hygiene problem #17

Merged
merged 9 commits into from
Dec 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/kubernetes_example/src/main.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
1 change: 1 addition & 0 deletions examples/local_queue_example/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
75 changes: 35 additions & 40 deletions turbolift_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HttpResponse> {
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<String> = 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<String> = 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
Expand Down