Skip to content

Commit

Permalink
Deleting subscriptions in parallel.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmackdev committed Aug 7, 2023
1 parent 0c6c5c4 commit e8c5439
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
29 changes: 29 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pubsubman_backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"

[dependencies]
chrono = { workspace = true }
futures = "0.3.28"
futures-util = "0.3.28"
google-cloud-googleapis = "0.10.0"
google-cloud-pubsub = "0.18.0"
Expand Down
13 changes: 8 additions & 5 deletions pubsubman_backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,18 @@ impl Backend {
FrontendMessage::DeleteSubscriptions(sub_names) => {
let back_tx = self.back_tx.clone();
rt.spawn(async move {
let client = create_client().await;
let mut futures = vec![];

// TODO: Do in parallel
for sub_name in sub_names.into_iter() {
let subscription = client.subscription(&sub_name.0);
let _ = subscription.delete(None).await;
println!("DELETED {}", &sub_name.0);
futures.push(async move {
let client = create_client().await;
let subscription = client.subscription(&sub_name.0);
let _ = subscription.delete(None).await;
});
}

futures::future::join_all(futures).await;

back_tx
.send(BackendMessage::SubscriptionsDeleted)
.await
Expand Down

0 comments on commit e8c5439

Please sign in to comment.