-
Notifications
You must be signed in to change notification settings - Fork 348
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
Allow running handler with a callback #694
Conversation
## What? This is a pretty naive approach that allows the end user to supply a callback that will be invoked once a single event loop has been finished. ## Why? Because currently there is no good way(that I know of) to flush logs/traces/metrics. By having a callback that is called after all event handling is finished allows the end user to do a cleanup at the end of each lambda invocation.
Thanks for the submission! In general I like this change, I think this is functionality we want to support. The current approach feels a bit disjointed - the callback is passed as an
thoughts? my initial impression is that i like option two better. |
@@ -202,7 +203,13 @@ where | |||
} | |||
.instrument(request_span) | |||
.await?; | |||
|
|||
if let Some(callback) = callback.clone() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you do the following to avoid the clone?
if let Some(ref callback) = callback {
...
}
This looks reasonable, but I'd like to have some time to see if we can find a solution that doesn't involve adding an extra function. Since functions gets translated into Tower services, there might be an opportunity to design this as another Tower integration that doesn't require any extra functionality in the runtime. |
See That said, working with Tower ended up being quite a chore between figuring out how to write |
Given that the current interface makes everyone make a call to build a tower service, it makes sense to solve this problem within the framework of |
Yeah I started prototyping what I had in mind, and one of the annoying things is that you can't build Tower middleware with standard async/await semantics. so we'd probably end up doing our own |
My bad, I had that backwards. Yeah the hook after the lambda function is what required writing my own Future. So yeah, doing this right now does require quite a bit of code. There might be a an easier way with tower::ServiceBuilder however I was unable to get that to work at the library scope. |
I don't think this is the direction that we want to take. We probably need to think a little bit more about how to layer this with Tower. I'm going to close this PR. Thanks a lot for the contribution. I hope we can make some improvements in this area in the future. |
What?
This is a pretty naive approach that allows the end user to supply a callback that will be invoked once a single event loop has been finished.
Why?
Because currently there is no good way(that I know of) to flush logs/traces/metrics. By having a callback that is called after all event handling is finished allows the end user to do a cleanup at the end of each lambda invocation.
See #691 for further context