From 28222dcd560f7d5cc78b6b4b12b47fad259b99a8 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Wed, 27 Mar 2024 11:25:46 +0800 Subject: [PATCH] Add more logging to youtube jobs --- .../api/src/jobs/process-youtube-video.ts | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/api/src/jobs/process-youtube-video.ts b/packages/api/src/jobs/process-youtube-video.ts index 6ffff1a03..07f3f5c3c 100644 --- a/packages/api/src/jobs/process-youtube-video.ts +++ b/packages/api/src/jobs/process-youtube-video.ts @@ -223,7 +223,7 @@ export const addTranscriptPlaceholdReadableContent = async ( async function readStringFromStorage( bucketName: string, fileName: string -): Promise { +): Promise { try { const storage = env.fileUpload?.gcsUploadSAKeyFilePath ? new Storage({ keyFilename: env.fileUpload.gcsUploadSAKeyFilePath }) @@ -247,12 +247,11 @@ async function readStringFromStorage( .file(fileName) .download() const fileContent = fileContentResponse[0].toString() - - console.log(`File '${fileName}' downloaded successfully as string.`) return fileContent } catch (error) { - console.error('Error downloading file:', error) - throw error + // This isn't a catastrophic error it just means the file doesn't exist + logger.info('Error downloading file:', error) + return undefined } } @@ -284,11 +283,11 @@ const writeStringToStorage = async ( .on('error', reject) }) - console.log( + logger.info( `File '${fileName}' uploaded successfully to bucket '${bucketName}'.` ) } catch (error) { - console.error('Error uploading file:', error) + logger.error('Error uploading file:', error) throw error } } @@ -334,6 +333,7 @@ const cacheYouTubeTranscript = async ( export const processYouTubeVideo = async ( jobData: ProcessYouTubeVideoJobData ) => { + let videoURL: URL | undefined try { const libraryItem = await authTrx( async (tx) => @@ -356,11 +356,11 @@ export const processYouTubeVideo = async ( return } - const u = new URL(libraryItem.originalUrl) - const videoId = u.searchParams.get('v') + videoURL = new URL(libraryItem.originalUrl) + const videoId = videoURL.searchParams.get('v') if (!videoId) { - console.warn('no video id for supplied youtube url', { + logger.warn('no video id for supplied youtube url', { url: libraryItem.originalUrl, }) return @@ -370,7 +370,7 @@ export const processYouTubeVideo = async ( const youtube = new YouTubeClient() const video = await youtube.getVideo(videoId) if (!video) { - console.warn('no video found for youtube url', { + logger.warn('no video found for youtube url', { url: libraryItem.originalUrl, }) return @@ -427,11 +427,11 @@ export const processYouTubeVideo = async ( jobData.userId ) if (!updated) { - console.warn('could not updated library item') + logger.warn('could not updated library item') } } } catch (err) { - console.warn('error creating summary: ', err) + logger.warn('error getting youtube metadata: ', { err, jobData, videoURL }) } } @@ -517,10 +517,10 @@ export const processYouTubeTranscript = async ( jobData.userId ) if (!updated) { - console.warn('could not updated library item') + logger.warn('could not updated library item') } } } catch (err) { - console.warn('error creating summary: ', err) + logger.warn('error getting youtube transcript: ', { err, jobData }) } }