@@ -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}
0 commit comments