Skip to content

fixed the issue of allSetled #37

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

Merged
merged 2 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 64 additions & 31 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"winston": "^3.1.0"
},
"engines": {
"node": "10.x"
"node": "14.x"
},
"standard": {
"ignore": [
Expand Down
16 changes: 10 additions & 6 deletions src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ async function filterMemberForGroups (memberIds, groupIds) {
const memberList = []

for (const memberId of memberIds) {
const res = await Promise.allSettled(groupIds.map(groupId => memberGroupsCall(groupId, memberId)))
const res = await Promise.all(groupIds.map(groupId => memberGroupsCall(groupId, memberId)))
const memberGroups = _.compact(_.flattenDeep(_.map(res, 'value')))

if (memberGroups.length !== groupIds.length) memberList.push(memberId)
Expand All @@ -216,12 +216,16 @@ async function filterMemberForGroups (memberIds, groupIds) {
async function memberGroupsCall (groupId, memberId) {
// M2M token is cached by 'tc-core-library-js' lib
const token = await getM2MToken()

const url = `${config.GROUPS_API_URL}/${groupId}/members/${memberId}`
return superagent
.get(url)
.set('Authorization', `Bearer ${token}`)
.timeout(config.REQUEST_TIMEOUT)

try {
return superagent
.get(url)
.set('Authorization', `Bearer ${token}`)
.timeout(config.REQUEST_TIMEOUT)
} catch (error) {
return []
}
}

module.exports = {
Expand Down
5 changes: 3 additions & 2 deletions src/services/ProcessorService.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async function handleChallengeUpdate (message) {
challengeResources = challengeResources.filter(member => filteredMemberIds.includes(member.memberId))

// remove members from resources who are not part of all the groups
await Promise.allSettled(challengeResources.map(member => helper.deleteResource(challengeId, member.memberHandle, config.RESOURCE_ROLE_ID)))
await Promise.all(challengeResources.map(member => helper.deleteResource(challengeId, member.memberHandle, config.RESOURCE_ROLE_ID)))
}

logger.info(`Successfully processed message of challenge id ${challengeId} and project id ${projectId}`)
Expand Down Expand Up @@ -177,7 +177,8 @@ handleMemberRemoved.schema = {
module.exports = {
handleChallengeCreate,
handleMemberAdded,
handleMemberRemoved
handleMemberRemoved,
handleChallengeUpdate
}

logger.buildService(module.exports)