-
Notifications
You must be signed in to change notification settings - Fork 732
chore: add duplicate organization pruning script [CM-766] #3597
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 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
116cba6
chore: add duplicate organization pruning script
skwowet ca67823
Merge branch 'main' into script/clean-duplicate-orgs
skwowet bd1a315
fix: resolve pr comments
skwowet fd852e4
chore: add script for pruning and refreshing member organizations
skwowet 241df9f
Merge branch 'main' into script/clean-duplicate-orgs
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
Some comments aren't visible on the classic Files Changed page.
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
41 changes: 0 additions & 41 deletions
41
services/apps/script_executor_worker/src/activities/cleanup/duplicate-members.ts
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
services/apps/script_executor_worker/src/activities/prune-duplicate-organizations.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,25 @@ | ||
| import OrganizationRepository from '@crowd/data-access-layer/src/old/apps/script_executor_worker/organization.repo' | ||
|
|
||
| import { svc } from '../main' | ||
|
|
||
| export async function pruneOrganization(orgId: string): Promise<void> { | ||
| try { | ||
| const orgRepo = new OrganizationRepository(svc.postgres.writer.connection(), svc.log) | ||
| await orgRepo.pruneOrganization(orgId) | ||
| } catch (error) { | ||
| svc.log.error(error, 'Error pruning organization in database!') | ||
| throw error | ||
| } | ||
| } | ||
|
|
||
| export async function getOrganizationsToPrune( | ||
| batchSize: number, | ||
| ): Promise<{ id: string; displayName: string }[]> { | ||
| try { | ||
| const orgRepo = new OrganizationRepository(svc.postgres.reader.connection(), svc.log) | ||
| return orgRepo.getOrganizationsToPrune(batchSize) | ||
| } catch (error) { | ||
| svc.log.error(error, 'Error getting organizations to prune!') | ||
| throw error | ||
| } | ||
| } |
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
64 changes: 0 additions & 64 deletions
64
services/apps/script_executor_worker/src/workflows/cleanup/duplicate-members.ts
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
services/apps/script_executor_worker/src/workflows/prune-duplicate-organizations.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,37 @@ | ||
| import { proxyActivities } from '@temporalio/workflow' | ||
|
|
||
| import * as activities from '../activities' | ||
| import { IScriptBatchTestArgs } from '../types' | ||
| import { chunkArray } from '../utils/common' | ||
|
|
||
| const { getOrganizationsToPrune, pruneOrganization, syncRemoveOrganization } = proxyActivities< | ||
| typeof activities | ||
| >({ | ||
| startToCloseTimeout: '30 minutes', | ||
| retry: { maximumAttempts: 3, backoffCoefficient: 3 }, | ||
| }) | ||
|
|
||
| export async function pruneDuplicateOrganizations(args: IScriptBatchTestArgs): Promise<void> { | ||
| const BATCH_SIZE = args.batchSize ?? 100 | ||
|
|
||
| const organizationsToPrune = await getOrganizationsToPrune(BATCH_SIZE) | ||
|
|
||
| if (organizationsToPrune.length === 0) { | ||
| console.log('No more organizations to prune!') | ||
| return | ||
| } | ||
|
|
||
| const CHUNK_SIZE = 25 | ||
|
|
||
| for (const chunk of chunkArray(organizationsToPrune, CHUNK_SIZE)) { | ||
| const cleanupTasks = chunk.map(async (o) => { | ||
| console.log('Pruning organization', o.displayName) | ||
| await syncRemoveOrganization(o.id) | ||
| return pruneOrganization(o.id) | ||
| }) | ||
|
|
||
| await Promise.all(cleanupTasks).catch((err) => { | ||
| console.error('Error pruning organizations!', err) | ||
| }) | ||
| } | ||
| } | ||
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
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.