Skip to content

Commit

Permalink
remove try catch block in organizationUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
epipav committed Aug 15, 2024
1 parent aef10ba commit cab2a95
Showing 1 changed file with 30 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,41 @@ organizationUpdate can do the following:
- Also sync organization aggregates to postgres (organizationSegmentsAgg table), if syncOptions.doSync is true AND syncOptions.withAggs is true.
*/
export async function organizationUpdate(input: IOrganizationProfileSyncInput): Promise<void> {
try {
// End early if recalculateAffiliations is false, only do syncing if necessary.
if (!input.recalculateAffiliations) {
if (input.syncOptions?.doSync) {
await syncOrganization(input.organization.id, input.syncOptions?.withAggs)
}
return
// End early if recalculateAffiliations is false, only do syncing if necessary.
if (!input.recalculateAffiliations) {
if (input.syncOptions?.doSync) {
await syncOrganization(input.organization.id, input.syncOptions?.withAggs)
}
return
}

const ORGANIZATION_MEMBER_AFFILIATIONS_UPDATED_PER_RUN = 500

const memberIds = await findMembersInOrganization(
input.organization.id,
ORGANIZATION_MEMBER_AFFILIATIONS_UPDATED_PER_RUN,
input.afterMemberId,
)
const ORGANIZATION_MEMBER_AFFILIATIONS_UPDATED_PER_RUN = 500

if (memberIds.length === 0) {
if (input.syncOptions?.doSync) {
// sync organization
await syncOrganization(input.organization.id, input.syncOptions?.withAggs)
}
return
}
const memberIds = await findMembersInOrganization(
input.organization.id,
ORGANIZATION_MEMBER_AFFILIATIONS_UPDATED_PER_RUN,
input.afterMemberId,
)

for (const memberId of memberIds) {
await updateMemberAffiliations({ member: { id: memberId } })
if (memberIds.length === 0) {
if (input.syncOptions?.doSync) {
// sync organization
await syncOrganization(input.organization.id, input.syncOptions?.withAggs)
}
return
}

console.log(`Continuing new with params:`)
console.log({
params: { ...input, afterMemberId: memberIds[memberIds.length - 1] },
})

await continueAsNew<typeof organizationUpdate>({
...input,
afterMemberId: memberIds[memberIds.length - 1],
})
} catch (err) {
throw new Error(err)
for (const memberId of memberIds) {
await updateMemberAffiliations({ member: { id: memberId } })
}

console.log(`Continuing new with params:`)
console.log({
params: { ...input, afterMemberId: memberIds[memberIds.length - 1] },
})

await continueAsNew<typeof organizationUpdate>({
...input,
afterMemberId: memberIds[memberIds.length - 1],
})
}

0 comments on commit cab2a95

Please sign in to comment.