Skip to content

Commit 1199eb5

Browse files
authored
fix: stabilize LFID enrichment child workflows under auth0 mutex (#4293)
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
1 parent 5fc149a commit 1199eb5

2 files changed

Lines changed: 27 additions & 22 deletions

File tree

services/apps/members_enrichment_worker/src/workflows/lf-auth0/enrichMemberWithLFAuth0.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import * as activities from '../../activities'
77
import { ILFIDEnrichmentGithubProfile } from '../../sources/lfid/types'
88

99
const {
10-
refreshToken,
1110
getEnrichmentLFAuth0,
1211
getIdentitiesExistInOtherMembers,
1312
updateMemberWithEnrichmentData,
@@ -22,8 +21,7 @@ const {
2221
},
2322
})
2423

25-
export async function enrichMemberWithLFAuth0(member: IMember): Promise<void> {
26-
const token = await refreshToken()
24+
export async function enrichMemberWithLFAuth0(token: string, member: IMember): Promise<void> {
2725
const enriched = await getEnrichmentLFAuth0(token, member)
2826

2927
if (enriched) {

services/apps/members_enrichment_worker/src/workflows/lf-auth0/getMembersForLFIDEnrichment.ts

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import {
66
proxyActivities,
77
} from '@temporalio/workflow'
88

9-
import { IMember } from '@crowd/types'
10-
119
import * as activities from '../../activities'
1210
import { IGetMembersForLFIDEnrichmentArgs } from '../../sources/lfid/types'
1311
import { enrichMemberWithLFAuth0 } from '../lf-auth0/enrichMemberWithLFAuth0'
@@ -16,6 +14,15 @@ const { getLFIDEnrichableMembers } = proxyActivities<typeof activities>({
1614
startToCloseTimeout: '10 seconds',
1715
})
1816

17+
const { refreshToken } = proxyActivities<typeof activities>({
18+
startToCloseTimeout: '2 minutes',
19+
retry: {
20+
initialInterval: '2 seconds',
21+
backoffCoefficient: 2,
22+
maximumAttempts: 3,
23+
},
24+
})
25+
1926
export async function getMembersForLFIDEnrichment(
2027
args: IGetMembersForLFIDEnrichmentArgs,
2128
): Promise<void> {
@@ -27,23 +34,23 @@ export async function getMembersForLFIDEnrichment(
2734
return
2835
}
2936

30-
await Promise.all(
31-
members.map((member: IMember) => {
32-
return executeChild(enrichMemberWithLFAuth0, {
33-
workflowId: 'member-enrichment-lfid/' + member.id,
34-
cancellationType: ChildWorkflowCancellationType.ABANDON,
35-
parentClosePolicy: ParentClosePolicy.PARENT_CLOSE_POLICY_ABANDON,
36-
workflowExecutionTimeout: '1 minute',
37-
retry: {
38-
backoffCoefficient: 2,
39-
maximumAttempts: 10,
40-
initialInterval: 2 * 1000,
41-
maximumInterval: 30 * 1000,
42-
},
43-
args: [member],
44-
})
45-
}),
46-
)
37+
const token = await refreshToken()
38+
39+
for (const member of members) {
40+
await executeChild(enrichMemberWithLFAuth0, {
41+
workflowId: 'member-enrichment-lfid/' + member.id,
42+
cancellationType: ChildWorkflowCancellationType.ABANDON,
43+
parentClosePolicy: ParentClosePolicy.PARENT_CLOSE_POLICY_ABANDON,
44+
workflowExecutionTimeout: '10 minutes',
45+
retry: {
46+
backoffCoefficient: 2,
47+
maximumAttempts: 10,
48+
initialInterval: 2 * 1000,
49+
maximumInterval: 30 * 1000,
50+
},
51+
args: [token, member],
52+
})
53+
}
4754

4855
await continueAsNew<typeof getMembersForLFIDEnrichment>({
4956
afterId: members[members.length - 1].id,

0 commit comments

Comments
 (0)