Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace all promise.All with promise.allSettled #122

Merged

Conversation

vbihun
Copy link
Contributor

@vbihun vbihun commented Sep 19, 2024

Description

Replaced all Promise.all with Promise.allSettled

Checklist

Please ensure that each of these items has been addressed:

  • I have tested these changes in my local environment
  • I have added/modified tests as applicable to cover these changes
  • (Atlassian contributors only) I have removed any Atlassian-internal changes including internal modules, references to internal tickets, and internal wiki links

@vbihun vbihun requested a review from a team as a code owner September 19, 2024 15:04
await Promise.all(groupIds.map((groupId) => disconnectGroup(groupId, cloudId, forgeAppId)));
const groupIds = await getGroupIds();

const result = await Promise.allSettled(groupIds.map((groupId) => disconnectGroup(groupId, cloudId, forgeAppId)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'd recommend to call these results since it's a collection.

@@ -3,6 +3,7 @@ import { getTrackingBranchName } from '../../../services/get-tracking-branch';
import { MergeRequestEvent } from '../../../types';
import { insertMetricValues } from '../../../services/insert-metric-values';
import { getMRCycleTime, getOpenMergeRequestsCount } from '../../../services/compute-event-and-metrics';
import { ALL_SETTLED_STATUS, getFormattedErrors } from '../../../utils/promise-allsettled-helpers';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea extracting these statuses to a constant.

src/services/clear-storage.ts Show resolved Hide resolved

const promisesResponse = await Promise.all(getDeploymentsPromises);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A single error here would have bubbled up. It looks like the new code is silently catching errors and returning an empty array. Do we want to change that behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, maybe better throw error in catch block, or remove try catch, because getDeploymentAfter28Days is used in hasDeploymentAfter28Days, and this method also is called in Promise.allSettled that is in try catch block. But the better option it's remove try catch block to stay the same logic

@vbihun vbihun merged commit f4b625e into atlassian-labs:main Sep 23, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants