Consistently use `whenCompleteAsync(…, migrationThreadPool)`

This commit is contained in:
Chris Eager 2021-09-03 11:58:27 -07:00 committed by Chris Eager
parent 6aadb4b458
commit dceebc1c8d
1 changed files with 9 additions and 4 deletions

View File

@ -340,18 +340,23 @@ public class AccountsDynamoDb extends AbstractDynamoDbStore implements AccountSt
final List<CompletableFuture<?>> futures = accounts.stream() final List<CompletableFuture<?>> futures = accounts.stream()
.map(this::migrate) .map(this::migrate)
.map(f -> f.whenComplete((migrated, e) -> { .map(f -> f.whenCompleteAsync((migrated, e) -> {
if (e == null) { if (e == null) {
MIGRATED_COUNTER.increment(migrated ? 1 : 0); MIGRATED_COUNTER.increment(migrated ? 1 : 0);
} else { } else {
ERROR_COUNTER.increment(); ERROR_COUNTER.increment();
} }
})) }, migrationThreadPool))
.collect(Collectors.toList()); .collect(Collectors.toList());
CompletableFuture<Void> migrationBatch = CompletableFuture.allOf(futures.toArray(new CompletableFuture[]{})); CompletableFuture<Void> migrationBatch = CompletableFuture.allOf(futures.toArray(new CompletableFuture[]{}));
return migrationBatch.whenComplete((result, exception) -> deleteRecentlyDeletedUuids()); return migrationBatch.whenCompleteAsync((result, exception) -> {
if (exception != null) {
logger.warn("Exception migrating batch", exception);
}
deleteRecentlyDeletedUuids();
}, migrationThreadPool);
} }
public void deleteRecentlyDeletedUuids() { public void deleteRecentlyDeletedUuids() {
@ -401,7 +406,7 @@ public class AccountsDynamoDb extends AbstractDynamoDbStore implements AccountSt
logger.error("Could not store account {}", account.getUuid()); logger.error("Could not store account {}", account.getUuid());
} }
resultFuture.completeExceptionally(exception); resultFuture.completeExceptionally(exception);
}); }, migrationThreadPool);
return resultFuture; return resultFuture;
} catch (Exception e) { } catch (Exception e) {
return CompletableFuture.failedFuture(e); return CompletableFuture.failedFuture(e);