appwrite-utils-cli
Version:
Appwrite Utility Functions to help with database management, data conversion, data import, migrations, and much more. Meant to be used as a CLI tool, I do not recommend installing this in frontend environments.
24 lines (23 loc) • 873 B
JavaScript
import { MessageFormatter } from "../shared/messageFormatter.js";
import { logger } from "../shared/logging.js";
export const retryFailedPromises = async (batch, maxRetries = 3) => {
const results = await Promise.allSettled(batch);
const toRetry = [];
results.forEach((result, index) => {
if (result.status === "rejected") {
logger.error("Promise rejected with reason:", { reason: result.reason });
if (maxRetries > 0) {
toRetry.push(batch[index]);
}
}
});
if (toRetry.length > 0) {
MessageFormatter.info(`Retrying ${toRetry.length} promises`, { prefix: "Retry" });
return retryFailedPromises(toRetry, maxRetries - 1);
}
else {
return results
.filter((result) => result.status === "fulfilled")
.map((result) => result);
}
};