Skip to content

Commit

Permalink
[7.11] [Application Usage] Use Promise.allSettled during rollups (#…
Browse files Browse the repository at this point in the history
…87675) (#87845)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
afharo and kibanamachine committed Jan 11, 2021
1 parent cb3a99e commit 1baef27
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,22 @@ export async function rollDailyData(logger: Logger, savedObjectsClient?: ISavedO
})),
{ overwrite: true }
);
await Promise.all(
const promiseStatuses = await Promise.allSettled(
rawApplicationUsageTransactional.map(
({ id }) => savedObjectsClient.delete(SAVED_OBJECTS_TRANSACTIONAL_TYPE, id) // There is no bulkDelete :(
)
);
const rejectedPromises = promiseStatuses.filter(
(settledResult): settledResult is PromiseRejectedResult =>
settledResult.status === 'rejected'
);
if (rejectedPromises.length > 0) {
throw new Error(
`Failed to delete some items in ${SAVED_OBJECTS_TRANSACTIONAL_TYPE}: ${JSON.stringify(
rejectedPromises.map(({ reason }) => reason)
)}`
);
}
}
} while (toCreate.size > 0);
} catch (err) {
Expand Down

0 comments on commit 1baef27

Please sign in to comment.