Created
July 19, 2019 17:43
-
-
Save bittrance/8f9fd9e2e61ef34f7f4ba844c4c6dbec to your computer and use it in GitHub Desktop.
Working loop_fn retries example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "rusoto_cwl_test" | |
version = "0.1.0" | |
authors = ["Bittrance <anders.qvist@burtcorp.com>"] | |
edition = "2018" | |
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
[dependencies] | |
futures = "0.1.25" | |
tokio-core = "0.1.17" | |
rusoto_core = "0.36.0" | |
rusoto_logs = "0.36.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use futures::future::{Future, loop_fn, Loop}; | |
use rusoto_core::{Region, RusotoFuture}; | |
use rusoto_logs::{CloudWatchLogs, CloudWatchLogsClient, DescribeLogStreamsRequest, DescribeLogStreamsResponse, DescribeLogStreamsError}; | |
use tokio_core::reactor::Core; | |
fn main() { | |
let mut core = Core::new().unwrap(); | |
let desc_streams_req = DescribeLogStreamsRequest { | |
log_group_name: "forbidden_group".into(), | |
..Default::default() | |
}; | |
let client = CloudWatchLogsClient::new(Region::EuWest1); | |
let task: RusotoFuture<DescribeLogStreamsResponse, DescribeLogStreamsError> = RusotoFuture::from_future( | |
loop_fn((client, desc_streams_req, 0u8), |(client, desc_streams_req, mut count)| { | |
client.describe_log_streams(desc_streams_req.clone()) | |
.and_then(|res| Ok(Loop::Break(res))) | |
.or_else(move |err| { | |
println!("{:?}", err); | |
count += 1; | |
if count >= 3 { | |
Err(err) | |
} else { | |
Ok(Loop::Continue((client, desc_streams_req, count))) | |
} | |
}) | |
}) | |
); | |
match core.run(task) { | |
Ok(item) => println!("item: {:?}", item), | |
Err(e) => panic!("Error completing futures: {}", e), | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment