From fd484056a404aa12c00a36b154331577ec3a6505 Mon Sep 17 00:00:00 2001 From: Philip Jenvey Date: Fri, 18 May 2018 12:20:00 -0700 Subject: [PATCH] refactor: fix our odd indents the multi line retry_ifs appears to trigger: https://github.com/rust-lang-nursery/rustfmt/issues/2368 so restrict them to one line when this happens Issue #1238 --- autopush_rs/src/db/commands.rs | 41 ++++++++++++++++------------------ autopush_rs/src/db/mod.rs | 33 +++++++++++++-------------- 2 files changed, 34 insertions(+), 40 deletions(-) diff --git a/autopush_rs/src/db/commands.rs b/autopush_rs/src/db/commands.rs index dcdf632e..0c7ffad0 100644 --- a/autopush_rs/src/db/commands.rs +++ b/autopush_rs/src/db/commands.rs @@ -52,10 +52,9 @@ pub fn fetch_messages( limit: Some(limit as i64), ..Default::default() }; - retry_if( - move || ddb.query(&input), - |err: &QueryError| matches!(err, &QueryError::ProvisionedThroughputExceeded(_)), - ).chain_err(|| "Error fetching messages") + let cond = |err: &QueryError| matches!(err, &QueryError::ProvisionedThroughputExceeded(_)); + retry_if(move || ddb.query(&input), cond) + .chain_err(|| "Error fetching messages") .and_then(|output| { let mut notifs: Vec = output.items.map_or_else(Vec::new, |items| { @@ -111,10 +110,9 @@ pub fn fetch_timestamp_messages( limit: Some(limit as i64), ..Default::default() }; - retry_if( - move || ddb.query(&input), - |err: &QueryError| matches!(err, &QueryError::ProvisionedThroughputExceeded(_)), - ).chain_err(|| "Error fetching messages") + let cond = |err: &QueryError| matches!(err, &QueryError::ProvisionedThroughputExceeded(_)); + retry_if(move || ddb.query(&input), cond) + .chain_err(|| "Error fetching messages") .and_then(|output| { let messages = output.items.map_or_else(Vec::new, |items| { debug!("Got response of: {:?}", items); @@ -247,20 +245,19 @@ pub fn all_channels( }, ..Default::default() }; - retry_if( - move || ddb.get_item(&input), - |err: &GetItemError| matches!(err, &GetItemError::ProvisionedThroughputExceeded(_)), - ).and_then(|output| { - let channels = output - .item - .and_then(|item| { - serde_dynamodb::from_hashmap::(item) - .ok() - .and_then(|notif| notif.chids) - }) - .unwrap_or_else(HashSet::new); - future::ok(channels) - }) + let cond = |err: &GetItemError| matches!(err, &GetItemError::ProvisionedThroughputExceeded(_)); + retry_if(move || ddb.get_item(&input), cond) + .and_then(|output| { + let channels = output + .item + .and_then(|item| { + serde_dynamodb::from_hashmap::(item) + .ok() + .and_then(|notif| notif.chids) + }) + .unwrap_or_else(HashSet::new); + future::ok(channels) + }) .or_else(|_err| future::ok(HashSet::new())) } diff --git a/autopush_rs/src/db/mod.rs b/autopush_rs/src/db/mod.rs index 41e61be3..0a4766fc 100644 --- a/autopush_rs/src/db/mod.rs +++ b/autopush_rs/src/db/mod.rs @@ -281,19 +281,17 @@ impl DynamoStorage { request_items: hashmap! { message_month.to_string() => put_items }, ..Default::default() }; - retry_if( - move || ddb.batch_write_item(&batch_input), - |err: &BatchWriteItemError| { - matches!(err, &BatchWriteItemError::ProvisionedThroughputExceeded(_)) - }, - ) + let cond = |err: &BatchWriteItemError| { + matches!(err, &BatchWriteItemError::ProvisionedThroughputExceeded(_)) + }; + retry_if(move || ddb.batch_write_item(&batch_input), cond) .and_then(|_| future::ok(())) - .map_err(|err| { - debug!("Error saving notification: {:?}", err); - err - }) - // TODO: Use Sentry to capture/report this error - .chain_err(|| "Error saving notifications") + .map_err(|err| { + debug!("Error saving notification: {:?}", err); + err + }) + // TODO: Use Sentry to capture/report this error + .chain_err(|| "Error saving notifications") } /// Delete a given notification from the database @@ -316,12 +314,11 @@ impl DynamoStorage { }, ..Default::default() }; - retry_if( - move || ddb.delete_item(&delete_input), - |err: &DeleteItemError| { - matches!(err, &DeleteItemError::ProvisionedThroughputExceeded(_)) - }, - ).and_then(|_| future::ok(())) + let cond = |err: &DeleteItemError| { + matches!(err, &DeleteItemError::ProvisionedThroughputExceeded(_)) + }; + retry_if(move || ddb.delete_item(&delete_input), cond) + .and_then(|_| future::ok(())) .chain_err(|| "Error deleting notification") }