Skip to content

Commit e18d366

Browse files
authored
Cleanup runtime config (#646)
- Move Config data into the Runtime struct - Make runtime methods private - Implement IntoRequest for EventCompletionStreamingRequest Signed-off-by: David Calavera <[email protected]>
1 parent 3fce312 commit e18d366

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

lambda-runtime/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ where
8787

8888
struct Runtime<C: Service<http::Uri> = HttpConnector> {
8989
client: Client<C>,
90+
config: Config,
9091
}
9192

9293
impl<C> Runtime<C>
@@ -96,11 +97,10 @@ where
9697
C::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
9798
C::Response: AsyncRead + AsyncWrite + Connection + Unpin + Send + 'static,
9899
{
99-
pub async fn run<F, A, B>(
100+
async fn run<F, A, B>(
100101
&self,
101102
incoming: impl Stream<Item = Result<http::Response<hyper::Body>, Error>> + Send,
102103
mut handler: F,
103-
config: &Config,
104104
) -> Result<(), Error>
105105
where
106106
F: Service<LambdaEvent<A>>,
@@ -125,7 +125,7 @@ where
125125
}
126126

127127
let ctx: Context = Context::try_from(parts.headers)?;
128-
let ctx: Context = ctx.with_config(config);
128+
let ctx: Context = ctx.with_config(&self.config);
129129
let request_id = &ctx.request_id.clone();
130130

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

259259
let client = &runtime.client;
260260
let incoming = incoming(client);
261-
runtime.run(incoming, handler, &config).await
261+
runtime.run(incoming, handler).await
262262
}
263263

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

525-
let runtime = Runtime { client };
525+
let runtime = Runtime { client, config };
526526
let client = &runtime.client;
527527
let incoming = incoming(client).take(1);
528-
runtime.run(incoming, f, &config).await?;
528+
runtime.run(incoming, f).await?;
529529

530530
// shutdown server
531531
tx.send(()).expect("Receiver has been dropped");
@@ -565,10 +565,10 @@ mod endpoint_tests {
565565
log_group: "test_log".to_string(),
566566
};
567567

568-
let runtime = Runtime { client };
568+
let runtime = Runtime { client, config };
569569
let client = &runtime.client;
570570
let incoming = incoming(client).take(1);
571-
runtime.run(incoming, f, &config).await?;
571+
runtime.run(incoming, f).await?;
572572

573573
match server.await {
574574
Ok(_) => Ok(()),

lambda-runtime/src/streaming.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ where
7272
trace!("Loading config from env");
7373
let config = Config::from_env()?;
7474
let client = Client::builder().build().expect("Unable to create a runtime client");
75-
let runtime = Runtime { client };
75+
let runtime = Runtime { client, config };
7676

7777
let client = &runtime.client;
7878
let incoming = incoming(client);
79-
runtime.run_with_streaming_response(incoming, handler, &config).await
79+
runtime.run_with_streaming_response(incoming, handler).await
8080
}
8181

8282
impl<C> Runtime<C>
@@ -86,11 +86,10 @@ where
8686
C::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
8787
C::Response: AsyncRead + AsyncWrite + Connection + Unpin + Send + 'static,
8888
{
89-
pub async fn run_with_streaming_response<F, A, B>(
89+
async fn run_with_streaming_response<F, A, B>(
9090
&self,
9191
incoming: impl Stream<Item = Result<Response<Body>, Error>> + Send,
9292
mut handler: F,
93-
config: &Config,
9493
) -> Result<(), Error>
9594
where
9695
F: Service<LambdaEvent<A>>,
@@ -117,7 +116,7 @@ where
117116
}
118117

119118
let ctx: Context = Context::try_from(parts.headers)?;
120-
let ctx: Context = ctx.with_config(config);
119+
let ctx: Context = ctx.with_config(&self.config);
121120
let request_id = &ctx.request_id.clone();
122121

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

207-
impl<'a, B> EventCompletionStreamingRequest<'a, B>
206+
impl<'a, B> IntoRequest for EventCompletionStreamingRequest<'a, B>
208207
where
209208
B: HttpBody + Unpin + Send + 'static,
210209
B::Data: Into<Bytes> + Send,

0 commit comments

Comments
 (0)