diff --git a/services/apps/profiles_worker/src/workflows/organization/organizationUpdate.ts b/services/apps/profiles_worker/src/workflows/organization/organizationUpdate.ts index 25881b64a0..99d11130b6 100644 --- a/services/apps/profiles_worker/src/workflows/organization/organizationUpdate.ts +++ b/services/apps/profiles_worker/src/workflows/organization/organizationUpdate.ts @@ -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 { - 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({ - ...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({ + ...input, + afterMemberId: memberIds[memberIds.length - 1], + }) }