Skip to content

Commit 64d1639

Browse files
committed
fix: code review suggestions
1 parent 4355b36 commit 64d1639

5 files changed

Lines changed: 28 additions & 21 deletions

File tree

services/apps/snowflake_connectors/src/core/integrationResolver.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const log = getServiceChildLogger('integrationResolver')
1717

1818
const CACHE_TTL_SECONDS = 24 * 60 * 60 // 24 hours
1919
const LOCK_TTL_SECONDS = 30
20+
const LOCK_WAIT_RETRIES = 5
21+
const LOCK_WAIT_BASE_MS = 200
2022

2123
export interface ResolvedIntegration {
2224
segmentId: string
@@ -121,20 +123,32 @@ export class IntegrationResolver {
121123
} else {
122124
log.info(
123125
{ platform, segmentId: segmentRow.id },
124-
'Lock held by another consumer, fetching existing',
125-
)
126-
integration = await this.db.oneOrNone<{ id: string }>(
127-
`SELECT id
128-
FROM integrations
129-
WHERE platform = $1
130-
AND "segmentId" = $2
131-
AND "deletedAt" IS NULL
132-
LIMIT 1`,
133-
[platform, segmentRow.id],
126+
'Lock held by another consumer, waiting for commit',
134127
)
128+
for (let attempt = 0; attempt < LOCK_WAIT_RETRIES; attempt++) {
129+
await new Promise((r) => setTimeout(r, LOCK_WAIT_BASE_MS * 2 ** attempt))
130+
integration = await this.db.oneOrNone<{ id: string }>(
131+
`SELECT id
132+
FROM integrations
133+
WHERE platform = $1
134+
AND "segmentId" = $2
135+
AND "deletedAt" IS NULL
136+
LIMIT 1`,
137+
[platform, segmentRow.id],
138+
)
139+
if (integration) break
140+
}
135141
}
136142
}
137143

144+
if (!integration) {
145+
log.warn(
146+
{ platform, segmentId: segmentRow.id },
147+
'Integration not found after lock contention, skipping',
148+
)
149+
return null
150+
}
151+
138152
const result: ResolvedIntegration = {
139153
segmentId: segmentRow.id,
140154
integrationId: integration.id,

services/apps/snowflake_connectors/src/integrations/cvent/transformer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class CventTransformer extends TransformerBase {
1616

1717
transformRow(row: Record<string, unknown>): TransformedActivity | null {
1818
const userName = (row.USERNAME as string | null)?.trim() || null
19-
const lfUsername = (row.LF_USERNAME as string | null)?.trim() || null
19+
const lfUsername = (row.LFID as string | null)?.trim() || null
2020
const fullName = (row.FULL_NAME as string | null)?.trim() || null
2121
const firstName = (row.FIRST_NAME as string | null)?.trim() || null
2222
const lastName = (row.LAST_NAME as string | null)?.trim() || null

services/apps/snowflake_connectors/src/integrations/index.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@ export function getPlatform(platform: PlatformType): PlatformDefinition {
4040
return supported[platform]
4141
}
4242

43-
export function getEnabledPlatformDefinitions(): PlatformDefinition[] {
44-
return enabled.map((platform) => {
45-
if (!supported[platform]) {
46-
throw new Error(`Enabled platform not supported: ${platform}`)
47-
}
48-
return supported[platform]
49-
})
50-
}
51-
5243
export function getEnabledPlatforms(): PlatformType[] {
5344
return enabled
5445
}

services/apps/snowflake_connectors/src/workflows/exportWorkflow.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { executeChild, proxyActivities } from '@temporalio/workflow'
2+
import { PlatformType } from '@crowd/types'
23

34
import type * as activities from '../activities/exportActivity'
45

@@ -35,6 +36,6 @@ export async function snowflakeS3ExportScheduler(): Promise<void> {
3536
await Promise.allSettled(childWorkflows)
3637
}
3738

38-
export async function exportSnowflakeData(platform: string): Promise<void> {
39+
export async function exportSnowflakeData(platform: PlatformType): Promise<void> {
3940
await executeExport(platform)
4041
}

services/libs/types/src/enums/organizations.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export enum OrganizationSource {
1212
ENRICHMENT_CRUSTDATA = 'enrichment-crustdata',
1313
GITHUB = 'github',
1414
UI = 'ui',
15+
CVENT = 'cvent',
1516
}
1617

1718
export enum OrganizationMergeSuggestionType {

0 commit comments

Comments
 (0)