rust-server-sdk icon indicating copy to clipboard operation
rust-server-sdk copied to clipboard

Return waitable future from Client::flush()

Open ramosbugs opened this issue 3 years ago • 2 comments

Is your feature request related to a problem? Please describe.

Currently, Client provides a flush method that can be used to flush pending analytics events. However, there is no way to await the flush to ensure that analytics events have completed without calling Client::close to completely destroy the client.

For serverless use cases in particular, it would be very helpful to be able to ensure that analytics events have been reported before allowing the (e.g., AWS Lambda) function to suspend and wait for the next request (which might never come, in which case the analytics events would be dropped).

Describe the solution you'd like

Have flush return a Future. A straightforward way to do this is in Rust is via a channel (e.g., futures::channel::oneshot).

ramosbugs avatar Feb 16 '22 01:02 ramosbugs

Thank you for the request and additional context. I have filed your request internally as sc-142482.

keelerm84 avatar Feb 16 '22 22:02 keelerm84

@keelerm84: It looks like 1.0.0 shipped without this change (see docs). This makes it very hard to use LaunchDarkly for Rust on AWS Lambda and still get analytics...

I had added a 2-second wait in a Lambda extension as a temporary workaround to hopefully allow time for flush() to complete before the Lambda function sleeps, but this turned out to add a significant cost to the AWS bill when factoring in hundreds of thousands or millions of Lambda invocations (easily $50-100/mo). For now I'm going to have to disable the flush wait and not get flag analytics.

Are there any plans to fully support serverless deployments with the Rust SDK?

ramosbugs avatar Dec 17 '22 04:12 ramosbugs