-
Notifications
You must be signed in to change notification settings - Fork 729
Script to fix member affiliations for deleted work experiences #2679
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
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
85ead90
add script to fix member affiliations
skwowet b16f19e
add console logs
skwowet ce938ef
Merge branch 'main' into script/fix-member-affiliations
skwowet 09ea087
update retry
skwowet e1c5ac8
Merge branch 'script/fix-member-affiliations' of github.com:CrowdDotD…
skwowet 9e8ced1
add memberIds log
skwowet 9da8d66
testRun
skwowet 748c9af
fix script worker
skwowet 94b1afd
fix script worker
skwowet 0e1599c
fix script worker
skwowet 7edce71
fix script worker
skwowet b6ebc8e
rm unnecessary logs
skwowet ed96ae1
Merge branch 'main' into script/fix-member-affiliations
skwowet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
services/apps/script_executor_worker/src/activities/fix-member-affiliations/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
67 changes: 67 additions & 0 deletions
67
services/apps/script_executor_worker/src/workflows/fixMemberAffiliations.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.