Skip to content

Cleanup runtime config #646

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

Merged
merged 1 commit into from
May 2, 2023
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
18 changes: 9 additions & 9 deletions lambda-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ where

struct Runtime<C: Service<http::Uri> = HttpConnector> {
client: Client<C>,
config: Config,
}

impl<C> Runtime<C>
Expand All @@ -96,11 +97,10 @@ where
C::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
C::Response: AsyncRead + AsyncWrite + Connection + Unpin + Send + 'static,
{
pub async fn run<F, A, B>(
async fn run<F, A, B>(
&self,
incoming: impl Stream<Item = Result<http::Response<hyper::Body>, Error>> + Send,
mut handler: F,
config: &Config,
) -> Result<(), Error>
where
F: Service<LambdaEvent<A>>,
Expand All @@ -125,7 +125,7 @@ where
}

let ctx: Context = Context::try_from(parts.headers)?;
let ctx: Context = ctx.with_config(config);
let ctx: Context = ctx.with_config(&self.config);
let request_id = &ctx.request_id.clone();

let request_span = match &ctx.xray_trace_id {
Expand Down Expand Up @@ -254,11 +254,11 @@ where
trace!("Loading config from env");
let config = Config::from_env()?;
let client = Client::builder().build().expect("Unable to create a runtime client");
let runtime = Runtime { client };
let runtime = Runtime { client, config };

let client = &runtime.client;
let incoming = incoming(client);
runtime.run(incoming, handler, &config).await
runtime.run(incoming, handler).await
}

fn type_name_of_val<T>(_: T) -> &'static str {
Expand Down Expand Up @@ -522,10 +522,10 @@ mod endpoint_tests {
}
let config = crate::Config::from_env().expect("Failed to read env vars");

let runtime = Runtime { client };
let runtime = Runtime { client, config };
let client = &runtime.client;
let incoming = incoming(client).take(1);
runtime.run(incoming, f, &config).await?;
runtime.run(incoming, f).await?;

// shutdown server
tx.send(()).expect("Receiver has been dropped");
Expand Down Expand Up @@ -565,10 +565,10 @@ mod endpoint_tests {
log_group: "test_log".to_string(),
};

let runtime = Runtime { client };
let runtime = Runtime { client, config };
let client = &runtime.client;
let incoming = incoming(client).take(1);
runtime.run(incoming, f, &config).await?;
runtime.run(incoming, f).await?;

match server.await {
Ok(_) => Ok(()),
Expand Down
11 changes: 5 additions & 6 deletions lambda-runtime/src/streaming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ where
trace!("Loading config from env");
let config = Config::from_env()?;
let client = Client::builder().build().expect("Unable to create a runtime client");
let runtime = Runtime { client };
let runtime = Runtime { client, config };

let client = &runtime.client;
let incoming = incoming(client);
runtime.run_with_streaming_response(incoming, handler, &config).await
runtime.run_with_streaming_response(incoming, handler).await
}

impl<C> Runtime<C>
Expand All @@ -86,11 +86,10 @@ where
C::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
C::Response: AsyncRead + AsyncWrite + Connection + Unpin + Send + 'static,
{
pub async fn run_with_streaming_response<F, A, B>(
async fn run_with_streaming_response<F, A, B>(
&self,
incoming: impl Stream<Item = Result<Response<Body>, Error>> + Send,
mut handler: F,
config: &Config,
) -> Result<(), Error>
where
F: Service<LambdaEvent<A>>,
Expand All @@ -117,7 +116,7 @@ where
}

let ctx: Context = Context::try_from(parts.headers)?;
let ctx: Context = ctx.with_config(config);
let ctx: Context = ctx.with_config(&self.config);
let request_id = &ctx.request_id.clone();

let request_span = match &ctx.xray_trace_id {
Expand Down Expand Up @@ -204,7 +203,7 @@ pub(crate) struct EventCompletionStreamingRequest<'a, B> {
pub(crate) body: Response<B>,
}

impl<'a, B> EventCompletionStreamingRequest<'a, B>
impl<'a, B> IntoRequest for EventCompletionStreamingRequest<'a, B>
where
B: HttpBody + Unpin + Send + 'static,
B::Data: Into<Bytes> + Send,
Expand Down