Skip to content
2 changes: 2 additions & 0 deletions services/apps/script_executor_worker/src/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
findMemberIdentitiesGroupedByPlatform,
findMemberMergeActions,
} from './activities/dissect-member'
import { getMemberIdsWithDeletedWorkexperiences } from './activities/fix-member-affiliations'
import {
deleteOrganizationIdentity,
findOrganizationIdentity,
Expand Down Expand Up @@ -38,4 +39,5 @@ export {
updateOrganizationIdentity,
deleteOrganizationIdentity,
isLfxMember,
getMemberIdsWithDeletedWorkexperiences,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import MemberRepository from '@crowd/data-access-layer/src/old/apps/script_executor_worker/member.repo'

import { svc } from '../../main'

export async function getMemberIdsWithDeletedWorkexperiences(limit: number, offset: number) {
let rows: string[] = []

try {
const memberRepo = new MemberRepository(svc.postgres.reader.connection(), svc.log)
rows = await memberRepo.getMemberIdsWithDeletedWorkexperience(limit, offset)
} catch (err) {
throw new Error(err)
}

return rows
}
6 changes: 6 additions & 0 deletions services/apps/script_executor_worker/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ export interface IFixOrgIdentitiesWithWrongUrlsArgs {
tenantId: string
testRun?: boolean
}

export interface IFixMemberAffiliationsArgs {
tenantId: string
offset?: number
testRun?: boolean
}
2 changes: 2 additions & 0 deletions services/apps/script_executor_worker/src/workflows.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { dissectMember } from './workflows/dissectMember'
import { findAndMergeMembersWithSamePlatformIdentitiesDifferentCapitalization } from './workflows/findAndMergeMembersWithSamePlatformIdentitiesDifferentCapitalization'
import { findAndMergeMembersWithSameVerifiedEmailsInDifferentPlatforms } from './workflows/findAndMergeMembersWithSameVerifiedEmailsInDifferentPlatforms'
import { fixMemberAffiliations } from './workflows/fixMemberAffiliations'
import { fixOrgIdentitiesWithWrongUrls } from './workflows/fixOrgIdentitiesWithWrongUrls'

export {
findAndMergeMembersWithSameVerifiedEmailsInDifferentPlatforms,
findAndMergeMembersWithSamePlatformIdentitiesDifferentCapitalization,
dissectMember,
fixOrgIdentitiesWithWrongUrls,
fixMemberAffiliations,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import {
ChildWorkflowCancellationType,
ParentClosePolicy,
continueAsNew,
executeChild,
proxyActivities,
} from '@temporalio/workflow'

import { TemporalWorkflowId } from '@crowd/types'

import * as activities from '../activities'
import { IFixMemberAffiliationsArgs } from '../types'

const { getMemberIdsWithDeletedWorkexperiences } = proxyActivities<typeof activities>({
startToCloseTimeout: '3 minute',
retry: { maximumAttempts: 3 },
})

export async function fixMemberAffiliations(args: IFixMemberAffiliationsArgs) {
const MEMBER_PAGE_SIZE = args.testRun ? 10 : 100
const offset = args.offset || 0

if (args.testRun) {
console.log(`Running in test mode with limit 10!`)
}

console.log(`Fixing affiliations with offset ${offset || 0}`)

const memberIds = await getMemberIdsWithDeletedWorkexperiences(MEMBER_PAGE_SIZE, offset)

if (memberIds.length === 0) {
console.log(`No members found with deleted worked experiences!`)
return
}

await Promise.all(
memberIds.map((id) => {
return executeChild('memberUpdate', {
taskQueue: 'profiles',
workflowId: `${TemporalWorkflowId.MEMBER_UPDATE}/${args.tenantId}/${id}`,
cancellationType: ChildWorkflowCancellationType.ABANDON,
parentClosePolicy: ParentClosePolicy.PARENT_CLOSE_POLICY_ABANDON,
retry: {
maximumAttempts: 10,
},
args: [
{
member: {
id,
},
},
],
searchAttributes: {
TenantId: [args.tenantId],
},
})
}),
)

if (!args.testRun) {
await continueAsNew<typeof fixMemberAffiliations>({
tenantId: args.tenantId,
offset: offset + MEMBER_PAGE_SIZE,
testRun: args.testRun,
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { DbConnection, DbTransaction } from '@crowd/database'
import { Logger } from '@crowd/logging'
import { IMember } from '@crowd/types'

import { IMemberId } from '../profiles_worker/types'

import { IFindMemberIdentitiesGroupedByPlatformResult, ISimilarMember } from './types'

class MemberRepository {
Expand Down Expand Up @@ -159,6 +161,32 @@ class MemberRepository {

return member
}

async getMemberIdsWithDeletedWorkexperience(limit: number, offset: number) {
let results: IMemberId[] = []
try {
results = await this.connection.query(
`
select distinct "memberId" as id
from "memberOrganizations"
where "deletedAt" is not null
order by id asc
limit $(limit)
offset $(offset);
`,
{
limit,
offset,
},
)
} catch (err) {
this.log.error('Error while finding members!', err)

throw new Error(err)
}

return results?.map((r) => r.id) || []
}
}

export default MemberRepository
Loading