Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
refactor: fix our odd indents
Browse files Browse the repository at this point in the history
the multi line retry_ifs appears to trigger:
rust-lang/rustfmt#2368

so restrict them to one line when this happens

Issue #1238
  • Loading branch information
pjenvey committed May 21, 2018
1 parent 7c9a837 commit fd48405
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 40 deletions.
41 changes: 19 additions & 22 deletions autopush_rs/src/db/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DynamoDbNotification> =
output.items.map_or_else(Vec::new, |items| {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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::<DynamoDbNotification>(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::<DynamoDbNotification>(item)
.ok()
.and_then(|notif| notif.chids)
})
.unwrap_or_else(HashSet::new);
future::ok(channels)
})
.or_else(|_err| future::ok(HashSet::new()))
}

Expand Down
33 changes: 15 additions & 18 deletions autopush_rs/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
}

Expand Down

0 comments on commit fd48405

Please sign in to comment.