Skip to content

Commit 76a4fed

Browse files
committed
chore: add debugger logs
1 parent 82d6c98 commit 76a4fed

4 files changed

Lines changed: 31 additions & 5 deletions

File tree

services/apps/organizations_enrichment_worker/src/main.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { Config } from '@crowd/archetype-standard'
22
import { Options, ServiceWorker } from '@crowd/archetype-worker'
33

4-
import { scheduleOrganizationsEnrichment } from './schedules'
4+
// import { scheduleOrganizationsEnrichment } from './schedules'
55

66
const config: Config = {
7-
envvars: ['CROWD_ORGANIZATION_ENRICHMENT_API_KEY'],
7+
envvars: [
8+
'CROWD_ORGANIZATION_ENRICHMENT_INTERNAL_API_URL',
9+
'CROWD_ORGANIZATION_ENRICHMENT_INTERNAL_API_KEY',
10+
],
811
producer: {
912
enabled: false,
1013
},
@@ -30,7 +33,7 @@ export const svc = new ServiceWorker(config, options)
3033
setImmediate(async () => {
3134
await svc.init()
3235

33-
await scheduleOrganizationsEnrichment()
36+
// await scheduleOrganizationsEnrichment()
3437

3538
await svc.start()
3639
})

services/apps/organizations_enrichment_worker/src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@ export interface IOrganizationEnrichmentDataNormalized {
4444
attributes?: Record<string, unknown>
4545
displayName?: string
4646
}
47+
48+
export interface IGetOrganizationsToEnrichInput {
49+
testRun?: boolean
50+
}

services/apps/organizations_enrichment_worker/src/workflows/enrichOrganization.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export async function enrichOrganization(
3636
const organization = await findOrganizationById(input.id)
3737
if (!organization) return
3838

39+
console.log('Enriching organization:', input.id)
40+
3941
const [cache] = await findOrganizationEnrichmentCache([source], input.id)
4042

4143
// Skip if cache is still fresh
@@ -44,6 +46,8 @@ export async function enrichOrganization(
4446
// Prepare enrichment input
4547
const enrichmentInput: IOrganizationEnrichmentSourceInput = await getEnrichmentInput(input)
4648

49+
console.log('Enrichment input:', enrichmentInput)
50+
4751
// Use LLM to pick the most relevant domain if multiple
4852
if (enrichmentInput.domains.length > 1) {
4953
const mostRelevantDomain = await selectMostRelevantDomainWithLLM(
@@ -58,34 +62,41 @@ export async function enrichOrganization(
5862
// Fetch new enrichment data
5963
const data = await getEnrichmentData(source, enrichmentInput)
6064

65+
console.log('Enrichment data:', JSON.stringify(data, null, 2))
66+
6167
// Record enrichment attempt
6268
await touchOrganizationEnrichmentLastTriedAt(input.id)
6369

6470
let changeInEnrichmentSourceData = false
6571

6672
if (!cache) {
6773
// First time enriching, create cache entry
74+
console.log('Creating cache entry for organization!')
6875
await createOrganizationEnrichmentCache(source, input.id, data)
6976
if (data) {
7077
changeInEnrichmentSourceData = true
7178
}
7279
} else if (cache && !data) {
7380
// No new data, keep the old cache and update the timestamp
81+
console.log('No new data, keeping old cache and updating timestamp!')
7482
await touchOrganizationEnrichmentCacheUpdatedAt(source, input.id)
7583
} else if (cache && data) {
7684
// Data changed, update cache
7785
if (sourceHasDifferentDataComparedToCache(cache, data)) {
86+
console.log('Data changed, updating cache!')
7887
await updateOrganizationEnrichmentCache(source, input.id, data)
7988
changeInEnrichmentSourceData = true
8089
} else {
8190
// Data unchanged, keep the old cache and update the timestamp
91+
console.log('Data unchanged, keeping old cache and updating timestamp!')
8292
await touchOrganizationEnrichmentCacheUpdatedAt(source, input.id)
8393
}
8494
}
8595

8696
// Apply enrichment only if there’s new data to apply
8797
if (changeInEnrichmentSourceData && data) {
8898
const normalized = await normalizeEnrichmentData(source, data)
99+
console.log('Normalized data:', JSON.stringify(normalized, null, 2))
89100
await applyEnrichmentToOrganization(input.id, normalized)
90101
}
91102
}

services/apps/organizations_enrichment_worker/src/workflows/getOrganizationsToEnrich.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import { IEnrichableOrganization, OrganizationEnrichmentSource } from '@crowd/types'
1010

1111
import * as activities from '../activities'
12+
import { IGetOrganizationsToEnrichInput } from '../types'
1213
import { chunkArray } from '../utils/common'
1314
import { enrichOrganization } from '../workflows'
1415

@@ -18,7 +19,9 @@ const { getEnrichableOrganizations, getMaxConcurrentRequests } = proxyActivities
1819
},
1920
)
2021

21-
export async function getOrganizationsToEnrich(): Promise<void> {
22+
export async function getOrganizationsToEnrich(
23+
input: IGetOrganizationsToEnrichInput,
24+
): Promise<void> {
2225
const QUERY_FOR_ENRICHABLE_ORGANIZATIONS_PER_RUN = 5
2326
const source = OrganizationEnrichmentSource.INTERNAL_API
2427

@@ -59,5 +62,10 @@ export async function getOrganizationsToEnrich(): Promise<void> {
5962
)
6063
}
6164

62-
await continueAsNew<typeof getOrganizationsToEnrich>()
65+
if (input.testRun) {
66+
console.log('Test run completed - stopping after first batch!')
67+
return
68+
}
69+
70+
await continueAsNew<typeof getOrganizationsToEnrich>({ ...input })
6371
}

0 commit comments

Comments
 (0)