-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add media download service (part 1) #104
Changes from 10 commits
34117b9
a524c85
53c0794
c20592b
1331600
c663acf
99fc2db
3d39603
1a8ecf4
322acaf
86ac652
ecff3ce
a7f1e8e
cc1248d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { spawn } from 'child_process'; | ||
import { logger } from './logging'; | ||
export interface ProcessResult { | ||
code?: number; | ||
stdout: string; | ||
stderr: string; | ||
} | ||
|
||
export const runSpawnCommand = ( | ||
processName: string, | ||
cmd: string, | ||
args: ReadonlyArray<string>, | ||
): Promise<ProcessResult> => { | ||
return new Promise((resolve, reject) => { | ||
const cp = spawn(cmd, args); | ||
const stdout: string[] = []; | ||
const stderr: string[] = []; | ||
cp.stdout.on('data', (data) => { | ||
stdout.push(data.toString()); | ||
}); | ||
|
||
cp.stderr.on('data', (data) => { | ||
stderr.push(data.toString()); | ||
}); | ||
|
||
cp.on('error', (e) => { | ||
stderr.push(e.toString()); | ||
}); | ||
|
||
cp.on('close', (code) => { | ||
const result = { | ||
stdout: stdout.join(''), | ||
stderr: stderr.join(''), | ||
code: code || undefined, | ||
}; | ||
logger.info('Ignoring stdout to avoid logging sensitive data'); | ||
logger.info(`process ${processName} stderr: ${result.stderr}`); | ||
if (code === 0) { | ||
resolve(result); | ||
} else { | ||
logger.error( | ||
`process ${processName} failed with code ${result.code} due to: ${result.stderr}`, | ||
); | ||
reject(result); | ||
} | ||
}); | ||
}); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,18 +66,18 @@ export const generateOutputSignedUrlAndSendMessage = async ( | |
originalFilename: string, | ||
inputSignedUrl: string, | ||
languageCode: LanguageCode, | ||
translate: boolean, | ||
translationRequested: boolean, | ||
zekehuntergreen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
): Promise<SendResult> => { | ||
const signedUrls = await generateOutputSignedUrls( | ||
s3Key, | ||
region, | ||
outputBucket, | ||
userEmail, | ||
7, | ||
translate, | ||
translationRequested, | ||
); | ||
|
||
const jobId = translate ? `${s3Key}-translation` : s3Key; | ||
const jobId = translationRequested ? `${s3Key}-translation` : s3Key; | ||
const job: TranscriptionJob = { | ||
id: jobId, // id of the source file | ||
inputSignedUrl, | ||
|
@@ -87,12 +87,32 @@ export const generateOutputSignedUrlAndSendMessage = async ( | |
originalFilename, | ||
outputBucketUrls: signedUrls, | ||
languageCode, | ||
translate, | ||
translate: false, | ||
}; | ||
return await sendMessage(client, queueUrl, JSON.stringify(job), s3Key); | ||
const messageResult = await sendMessage( | ||
client, | ||
queueUrl, | ||
JSON.stringify(job), | ||
s3Key, | ||
); | ||
if (isSqsFailure(messageResult) && translationRequested) { | ||
logger.info( | ||
`Failed to send message, error message: ${messageResult.errorMsg}`, | ||
); | ||
return messageResult; | ||
} | ||
if (!isSqsFailure(messageResult) && translationRequested) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might want to log an error if messageResult is an sqs failure |
||
return await sendMessage( | ||
client, | ||
queueUrl, | ||
JSON.stringify({ ...job, translate: true }), | ||
s3Key, | ||
); | ||
Comment on lines
+105
to
+110
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I understand this bit - we put two messages in the queue if the user has requested a translation? Doesn't the worker create the translation as its transcribing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The way translation works at the moment is that we send two messages and the translation runs on one worker, the normal transcription on the other. My idea there was to speed up the transcription/translation - if we do it all on the same worker then it could take twice as long There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ok thanks, I hadn't realized this. |
||
} | ||
return messageResult; | ||
}; | ||
|
||
const sendMessage = async ( | ||
export const sendMessage = async ( | ||
client: SQSClient, | ||
queueUrl: string, | ||
messageBody: string, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it important not to log stdout when running yt-dlp?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I've updated this ecff3ce