Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 134
CON-402 CN Remove all synchronous disk ops#3908
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
519b0c9088cdafaada9818fe43a53a3993d6d009b05aa25f41a282f7cb33a23183d8f2File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| const config = require('./config') | ||
| const fs = require('fs') | ||
| const fs = require('fs-extra') | ||
| const path = require('path') | ||
| const ffmpeg = require('ffmpeg-static').path | ||
| const spawn = require('child_process').spawn | ||
| @@ -13,7 +13,7 @@ const { logger: genericLogger } = require('./logging') | ||
| * @param {string} params.fileDir the directory of the uploaded track artifact | ||
| * @param {string} params.fileName the uploaded track artifact filename | ||
| * @param {Object} params.logContext the log context used to instantiate a logger | ||
| * @returns {Object} response in the structure | ||
| * @returns {Promise<Object>} response in the structure | ||
| { | ||
| segments: { | ||
| fileNames: segmentFileNames {string[]}: the segment file names only, | ||
| @@ -24,6 +24,7 @@ const { logger: genericLogger } = require('./logging') | ||
| */ | ||
| function segmentFile(fileDir, fileName, { logContext }) { | ||
| const logger = genericLogger.child(logContext) | ||
| return new Promise((resolve, reject) => { | ||
| const absolutePath = path.resolve(fileDir, fileName) | ||
| logger.info(`Segmenting file ${absolutePath}...`) | ||
| @@ -63,24 +64,27 @@ function segmentFile(fileDir, fileName, { logContext }) { | ||
| proc.stderr.on('data', (data) => (stderr += data.toString())) | ||
| proc.on('close', (code) => { | ||
| if (code === 0) { | ||
| const segmentFileNames = fs.readdirSync(fileDir + '/segments') | ||
| const segmentFilePaths = segmentFileNames.map((filename) => | ||
| path.resolve(fileDir, 'segments', filename) | ||
| ) | ||
| async function asyncFn() { | ||
| if (code === 0) { | ||
| const segmentFileNames = await fs.readdir(fileDir + '/segments') | ||
SidSethi marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const segmentFilePaths = segmentFileNames.map((filename) => | ||
| path.resolve(fileDir, 'segments', filename) | ||
| ) | ||
| resolve({ | ||
| segments: { | ||
| fileNames: segmentFileNames, | ||
| filePaths: segmentFilePaths | ||
| }, | ||
| m3u8FilePath | ||
| }) | ||
| } else { | ||
| logger.error('Error when processing file with ffmpeg') | ||
| logger.error('Command stdout:', stdout, '\nCommand stderr:', stderr) | ||
| reject(new Error('FFMPEG Error')) | ||
| resolve({ | ||
| segments: { | ||
| fileNames: segmentFileNames, | ||
| filePaths: segmentFilePaths | ||
| }, | ||
| m3u8FilePath | ||
| }) | ||
| } else { | ||
| logger.error('Error when processing file with ffmpeg') | ||
| logger.error('Command stdout:', stdout, '\nCommand stderr:', stderr) | ||
| reject(new Error('FFMPEG Error')) | ||
| } | ||
| } | ||
| asyncFn() | ||
| }) | ||
| }) | ||
| } | ||
| @@ -92,21 +96,22 @@ function segmentFile(fileDir, fileName, { logContext }) { | ||
| * @param {string} params.fileDir the directory of the uploaded track artifact | ||
| * @param {string} params.fileName the uploaded track artifact filename | ||
| * @param {Object} params.logContext the log context used to instantiate a logger | ||
| * @returns {string} the path to the transcode | ||
| * @returns {Promise<string>} the path to the transcode | ||
| */ | ||
| function transcodeFileTo320(fileDir, fileName, { logContext }) { | ||
| async function transcodeFileTo320(fileDir, fileName, { logContext }) { | ||
| const logger = genericLogger.child(logContext) | ||
| return new Promise((resolve, reject) => { | ||
| const sourcePath = path.resolve(fileDir, fileName) | ||
| const targetPath = path.resolve(fileDir, fileName.split('.')[0] + '-dl.mp3') | ||
| logger.info(`Transcoding file ${sourcePath}...`) | ||
| // Exit if dl-copy file already exists at target path. | ||
| if (fs.existsSync(targetPath)) { | ||
| logger.info(`Downloadable copy already exists at ${targetPath}.`) | ||
| resolve(targetPath) | ||
| } | ||
| const sourcePath = path.resolve(fileDir, fileName) | ||
| const targetPath = path.resolve(fileDir, fileName.split('.')[0] + '-dl.mp3') | ||
| logger.info(`Transcoding file ${sourcePath}...`) | ||
| // Exit if dl-copy file already exists at target path. | ||
| if (await fs.pathExists(targetPath)) { | ||
| logger.info(`Downloadable copy already exists at ${targetPath}.`) | ||
| return targetPath | ||
| } | ||
| return new Promise((resolve, reject) => { | ||
| // https://ffmpeg.org/ffmpeg-formats.html#hls-2 | ||
| const args = [ | ||
| '-i', | ||
| @@ -130,20 +135,23 @@ function transcodeFileTo320(fileDir, fileName, { logContext }) { | ||
| proc.stderr.on('data', (data) => (stderr += data.toString())) | ||
| proc.on('close', (code) => { | ||
| if (code === 0) { | ||
| if (fs.existsSync(targetPath)) { | ||
| logger.info(`Transcoded file ${targetPath}`) | ||
| resolve(targetPath) | ||
| async function asyncFn() { | ||
| if (code === 0) { | ||
| if (await fs.pathExists(targetPath)) { | ||
| logger.info(`Transcoded file ${targetPath}`) | ||
| resolve(targetPath) | ||
| } else { | ||
| logger.error('Error when processing file with ffmpeg') | ||
| logger.error('Command stdout:', stdout, '\nCommand stderr:', stderr) | ||
| reject(new Error('FFMPEG Error')) | ||
| } | ||
| } else { | ||
| logger.error('Error when processing file with ffmpeg') | ||
| logger.error('Command stdout:', stdout, '\nCommand stderr:', stderr) | ||
| reject(new Error('FFMPEG Error')) | ||
| } | ||
| } else { | ||
| logger.error('Error when processing file with ffmpeg') | ||
| logger.error('Command stdout:', stdout, '\nCommand stderr:', stderr) | ||
| reject(new Error('FFMPEG Error')) | ||
| } | ||
| asyncFn() | ||
| }) | ||
| }) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.