-
Notifications
You must be signed in to change notification settings - Fork 727
fix misattributed activities based on username + memberId #2715
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 11 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
f971344
fix miattributed activities based on username + memberId
skwowet 4ae5d0c
fix
skwowet 696ed05
increase startToClose
skwowet e883261
include tenantId
skwowet 02c0dbd
update query
skwowet b4d3120
update query
skwowet 5e9f3ee
Merge branch 'main' into script/LFX-1846
skwowet dfc6a56
improve script
skwowet b06c544
make linter happy
skwowet 0c7382c
fix
skwowet d5e21e9
Merge branch 'main' into script/LFX-1846
skwowet e217fe0
update in questdb
skwowet 56c4ee6
batch
skwowet 3644f91
update script
skwowet 1bc2a48
fix script worker
skwowet 6566479
update script
skwowet cfea6fa
increase timeout
skwowet 4804b58
donot use updateActivities
skwowet 47611cf
fix script worker
skwowet 6c520c2
fix rest of the members
skwowet 092621f
fix
skwowet 21de66b
fix
skwowet 6fa6ea8
update updatedAt for fixed activities
skwowet ee4156e
update script
skwowet 861f177
fix
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
40 changes: 40 additions & 0 deletions
40
services/apps/script_executor_worker/src/activities/fix-misattributed-activities/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,40 @@ | ||
| import { ActivityRepository } from '@crowd/data-access-layer/src/old/apps/script_executor_worker/activities.repo' | ||
| import MemberRepository from '@crowd/data-access-layer/src/old/apps/script_executor_worker/member.repo' | ||
| import { IActivityCreateData, IMemberIdentity } from '@crowd/types' | ||
|
|
||
| import { svc } from '../../main' | ||
|
|
||
| export async function findActivitiesWithWrongMembers(tenantId: string, limit: number) { | ||
| let activitiesWithWrongMember: IActivityCreateData[] = [] | ||
|
|
||
| try { | ||
| const activityRepo = new ActivityRepository(svc.postgres.reader.connection(), svc.log) | ||
| activitiesWithWrongMember = await activityRepo.getActivitiesWithWrongMembers(tenantId, limit) | ||
| } catch (err) { | ||
| throw new Error(err) | ||
| } | ||
|
|
||
| return activitiesWithWrongMember | ||
| } | ||
|
|
||
| export async function findMemberIdentity(username: string, platform: string, tenantId: string) { | ||
| let memberIdentity: IMemberIdentity | ||
|
|
||
| try { | ||
| const memberRepo = new MemberRepository(svc.postgres.reader.connection(), svc.log) | ||
| memberIdentity = await memberRepo.findMemberIdentity(username, platform, tenantId) | ||
| } catch (err) { | ||
| throw new Error(err) | ||
| } | ||
|
|
||
| return memberIdentity | ||
| } | ||
|
|
||
| export async function updateActivityWithWrongMember(activityId: string, correctMemberId: string) { | ||
| try { | ||
| const activityRepo = new ActivityRepository(svc.postgres.writer.connection(), svc.log) | ||
| await activityRepo.updateActivityWithWrongMember(activityId, correctMemberId) | ||
| } catch (err) { | ||
| throw new Error(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
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 { fixMisattributedActivities } from './workflows/fixMisattributedActivities' | ||
| import { fixOrgIdentitiesWithWrongUrls } from './workflows/fixOrgIdentitiesWithWrongUrls' | ||
|
|
||
| export { | ||
| findAndMergeMembersWithSameVerifiedEmailsInDifferentPlatforms, | ||
| findAndMergeMembersWithSamePlatformIdentitiesDifferentCapitalization, | ||
| dissectMember, | ||
| fixOrgIdentitiesWithWrongUrls, | ||
| fixMisattributedActivities, | ||
| } |
45 changes: 45 additions & 0 deletions
45
services/apps/script_executor_worker/src/workflows/fixMisattributedActivities.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,45 @@ | ||
| import { continueAsNew, proxyActivities } from '@temporalio/workflow' | ||
|
|
||
| import * as activities from '../activities' | ||
| import { IFixMisattributedActivitiesArgs } from '../types' | ||
|
|
||
| const activity = proxyActivities<typeof activities>({ | ||
| startToCloseTimeout: '10 minute', | ||
| retry: { maximumAttempts: 3 }, | ||
| }) | ||
|
|
||
| export async function fixMisattributedActivities( | ||
| args: IFixMisattributedActivitiesArgs, | ||
| ): Promise<void> { | ||
| const PROCESS_ACTIVITIES_PER_RUN = args.testRun ? 10 : 1000 | ||
|
|
||
| if (args.testRun) { | ||
| console.log(`Running in test mode with limit 10!`) | ||
| } | ||
|
|
||
| const tenantId = args.tenantId | ||
|
|
||
| const activitiesWithWrongMember = await activity.findActivitiesWithWrongMembers( | ||
| tenantId, | ||
| PROCESS_ACTIVITIES_PER_RUN, | ||
| ) | ||
|
|
||
| if (!activitiesWithWrongMember.length) { | ||
| console.log(`No activities found with misattributed members!`) | ||
| return | ||
| } | ||
|
|
||
| for (const a of activitiesWithWrongMember) { | ||
| const memberIdentity = await activity.findMemberIdentity(a.username, a.platform, tenantId) | ||
| if (memberIdentity) { | ||
| await activity.updateActivityWithWrongMember(a.id, memberIdentity.memberId) | ||
| } | ||
| } | ||
|
|
||
| if (!args.testRun) { | ||
| await continueAsNew<typeof fixMisattributedActivities>({ | ||
| testRun: args.testRun, | ||
| tenantId: args.tenantId, | ||
| }) | ||
| } | ||
| } |
61 changes: 61 additions & 0 deletions
61
services/libs/data-access-layer/src/old/apps/script_executor_worker/activities.repo.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,61 @@ | ||
| import { DbConnection, DbTransaction } from '@crowd/database' | ||
| import { Logger } from '@crowd/logging' | ||
| import { IActivityCreateData } from '@crowd/types' | ||
|
|
||
| export class ActivityRepository { | ||
| constructor( | ||
| private readonly connection: DbConnection | DbTransaction, | ||
| private readonly log: Logger, | ||
| ) {} | ||
|
|
||
| async getActivitiesWithWrongMembers( | ||
| tenantId: string, | ||
| limit = 100, | ||
| ): Promise<IActivityCreateData[]> { | ||
| try { | ||
| return await this.connection.query( | ||
| ` | ||
| SELECT | ||
| a.id, | ||
| a.username, | ||
| a.platform | ||
| FROM activities a | ||
| JOIN "memberIdentities" mi ON a.username = mi.value | ||
| AND a.platform = mi.platform | ||
| AND mi.type = 'username' | ||
| AND mi."verified" = true | ||
| AND a."tenantId" = mi."tenantId" | ||
| WHERE a."memberId" <> mi."memberId" | ||
| AND a."tenantId" = $(tenantId) | ||
| LIMIT $(limit) | ||
| `, | ||
| { | ||
| tenantId, | ||
| limit, | ||
| }, | ||
| ) | ||
| } catch (err) { | ||
| this.log.error('Error while finding activities!', err) | ||
| throw new Error(err) | ||
| } | ||
| } | ||
|
|
||
| async updateActivityWithWrongMember(activityId: string, correctMemberId: string): Promise<void> { | ||
| try { | ||
| await this.connection.none( | ||
| ` | ||
| UPDATE activities | ||
| SET "memberId" = $(correctMemberId) | ||
| WHERE id = $(activityId) | ||
| `, | ||
| { | ||
| correctMemberId, | ||
| activityId, | ||
| }, | ||
| ) | ||
| } catch (err) { | ||
| this.log.error('Error while updating activities!', err) | ||
| throw new Error(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
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.