changes to implement instructions
This commit is contained in:
@@ -10,6 +10,7 @@ const sqs = require('../app/services/sqs')
|
||||
const s3 = require('../app/services/s3')
|
||||
const voiceCloningService = require('./voice_cloning')
|
||||
const userAudioProfileService = require('./user_audio_profile')
|
||||
const { requireUserId, requireDocumentId } = require('../worker-tenant')
|
||||
|
||||
AWS.config.update({ region: 'us-west-2' })
|
||||
const sqsQueueUrl = process.env.SQS_URL
|
||||
@@ -101,14 +102,15 @@ const processQueue = () => {
|
||||
const receiptHandle = response.Messages[0].ReceiptHandle
|
||||
console.log('job===', job)
|
||||
|
||||
const { metadata, input, _id, userAudioProfileId } = job._doc
|
||||
const { _id, userAudioProfileId, userId } = job._doc
|
||||
requireUserId(userId)
|
||||
requireDocumentId(_id)
|
||||
requireDocumentId(userAudioProfileId)
|
||||
console.log('userAudioProfileId', userAudioProfileId)
|
||||
console.log('_id', _id)
|
||||
const { env } = job
|
||||
console.log('env', env)
|
||||
|
||||
console.log('metadata------', metadata)
|
||||
console.log('input', input)
|
||||
const DB_URI =
|
||||
env === 'production'
|
||||
? mongoUriProd
|
||||
@@ -126,9 +128,26 @@ const processQueue = () => {
|
||||
? cloudFrontUrlStaging
|
||||
: cloudFrontUrlDev
|
||||
|
||||
let authorized = false
|
||||
try {
|
||||
await sqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)
|
||||
|
||||
const cloningJob = await voiceCloningService.read({
|
||||
_id,
|
||||
userId,
|
||||
userAudioProfileId,
|
||||
})
|
||||
const audioProfile = await userAudioProfileService.read({
|
||||
_id: userAudioProfileId,
|
||||
userId,
|
||||
})
|
||||
if (!cloningJob || !audioProfile) {
|
||||
throw new Error('Cloning job or audio profile does not belong to user')
|
||||
}
|
||||
authorized = true
|
||||
|
||||
const { metadata, input } = cloningJob
|
||||
|
||||
const { directoryName } = metadata
|
||||
console.log('directoryName', directoryName)
|
||||
const logPath = `/mnt/efs/potion-voice/${env}/${directoryName}`
|
||||
@@ -136,9 +155,10 @@ const processQueue = () => {
|
||||
fs.mkdirSync(logPath, { recursive: true })
|
||||
}
|
||||
// update the db model to processing
|
||||
await voiceCloningService.update({ _id, status: 'processing' })
|
||||
await voiceCloningService.update({ _id, userId, status: 'processing' })
|
||||
await userAudioProfileService.update({
|
||||
_id: userAudioProfileId,
|
||||
userId,
|
||||
status: 'processing',
|
||||
})
|
||||
|
||||
@@ -240,7 +260,7 @@ const processQueue = () => {
|
||||
console.timeEnd(VOICE_MINIMIZE_LABEL)
|
||||
|
||||
// Add the code to update location of generated model and status into DB
|
||||
await voiceCloningService.update({ _id, status: 'completed' })
|
||||
await voiceCloningService.update({ _id, userId, status: 'completed' })
|
||||
|
||||
const training_model_path = {
|
||||
voice_model_path: `${resultsPath}/${generatedDirectoryName}/checkpoint_365200.pth`,
|
||||
@@ -252,6 +272,7 @@ const processQueue = () => {
|
||||
|
||||
await userAudioProfileService.update({
|
||||
_id: userAudioProfileId,
|
||||
userId,
|
||||
status: 'completed',
|
||||
training_model_path,
|
||||
})
|
||||
@@ -273,6 +294,7 @@ const processQueue = () => {
|
||||
// add S3 path to user audio profile model
|
||||
await userAudioProfileService.update({
|
||||
_id: userAudioProfileId,
|
||||
userId,
|
||||
training_model_s3_path,
|
||||
})
|
||||
} catch (error) {
|
||||
@@ -285,11 +307,14 @@ const processQueue = () => {
|
||||
Bugsnag.notify(error)
|
||||
|
||||
// update the db to set status as error
|
||||
await voiceCloningService.update({ _id, status: 'error' })
|
||||
await userAudioProfileService.update({
|
||||
_id: userAudioProfileId,
|
||||
status: 'error',
|
||||
})
|
||||
if (authorized) {
|
||||
await voiceCloningService.update({ _id, userId, status: 'error' })
|
||||
await userAudioProfileService.update({
|
||||
_id: userAudioProfileId,
|
||||
userId,
|
||||
status: 'error',
|
||||
})
|
||||
}
|
||||
|
||||
resolve() // to continue working on new jobs
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user