Commit b2b65d38 authored by A. Koch's avatar A. Koch

add error reporting for jobs

parent 8fbe8e0c
Pipeline #1110 passed with stage
......@@ -2,6 +2,8 @@ code_quality:
image: docker:stable
tags:
- motionbank
variables:
DOCKER_DRIVER: overlay2
allow_failure: true
services:
- docker:stable-dind
......
......@@ -882,9 +882,9 @@
"integrity": "sha1-+IiQMGhcfE/54qVZ9Qd+t2qBb5Y="
},
"colors": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/colors/-/colors-1.3.1.tgz",
"integrity": "sha512-jg/vxRmv430jixZrC+La5kMbUWqIg32/JsYNZb94+JEmzceYbWKTsv1OuTp+7EaqiaWRR2tPcykibwCRgclIsw=="
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/colors/-/colors-1.3.2.tgz",
"integrity": "sha512-rhP0JSBGYvpcNQj4s5AdShMeE5ahMop96cTeDl/v9qQQm2fYClE2QXZRi8wLzc+GmXSxdIqqbOIAhyObEXDbfQ=="
},
"colorspace": {
"version": "1.1.1",
......@@ -2650,9 +2650,9 @@
}
},
"mbjs-generic-api": {
"version": "0.0.9",
"resolved": "https://registry.npmjs.org/mbjs-generic-api/-/mbjs-generic-api-0.0.9.tgz",
"integrity": "sha512-y2o5h7S4289d6NHqkpVRho9AwT+Qwfr+Q30ggmhZILGV6sEVGqhHNj4OYs5aehQZRin6NRlYIwqicnAah8//QA==",
"version": "0.0.10",
"resolved": "https://registry.npmjs.org/mbjs-generic-api/-/mbjs-generic-api-0.0.10.tgz",
"integrity": "sha512-VGBxAVl5GCavTNug70RUcyI05l3Ja8R+7uZXzQc+IzgQ/zxTQB7yRvuOrktTFOUa9qdsZIW+OZZU8lfikkSD8g==",
"requires": {
"@polka/send-type": "^0.4.0",
"acl": "^0.4.11",
......
......@@ -6,12 +6,15 @@ const
ffmpegJoin = require('mbjs-media/src/util/ffmpeg-join'),
ffmpegThumb = require('mbjs-media/src/util/ffmpeg-thumb'),
Minio = require('minio'),
{ Assert, ObjectUtil } = require('mbjs-utils')
{ Assert, ObjectUtil } = require('mbjs-utils'),
{ captureException } = require('mbjs-generic-api/src/raven')
const concatJob = async function (job) {
Assert.ok(Array.isArray(job.data.sources), 'invalid sources')
const uuid = ObjectUtil.uuid4()
let errored = false
const uuid = job.data || ObjectUtil.uuid4()
const tmpDir = path.join(os.tmpdir(), uuid)
const destFile = `${uuid}.mp4`
const destination = path.join(tmpDir, destFile)
......@@ -26,29 +29,39 @@ const concatJob = async function (job) {
job.progress(progress.percent * 0.4)
})
} catch (e) {
console.error(e.message)
captureException(e)
errored = true
}
await ffmpegThumb(destination, tmpDir, 1, progress => {
job.progress(60 + progress.percent * 0.3)
})
const thumbFile = `${baseName}.jpg`
const thumbPath = path.join(path.dirname(destination), thumbFile)
await image.convert(path.join(tmpDir, 'tn.png'), thumbPath)
try {
await ffmpegThumb(destination, tmpDir, 1, progress => {
job.progress(60 + progress.percent * 0.3)
})
const thumbFileSmall = `${baseName}-s.jpg`
const thumbPathSmall = path.join(path.dirname(destination), thumbFileSmall)
await image.convert(path.join(tmpDir, 'tn.png'), thumbPathSmall, { resize: { width: 240, height: 240 } })
const thumbFile = `${baseName}.jpg`
const thumbPath = path.join(path.dirname(destination), thumbFile)
await image.convert(path.join(tmpDir, 'tn.png'), thumbPath)
const thumbFileMedium = `${baseName}-m.jpg`
const thumbPathMedium = path.join(path.dirname(destination), thumbFileMedium)
await image.convert(path.join(tmpDir, 'tn.png'), thumbPathMedium, { resize: { width: 640, height: 640 } })
const thumbFileSmall = `${baseName}-s.jpg`
const thumbPathSmall = path.join(path.dirname(destination), thumbFileSmall)
await image.convert(path.join(tmpDir, 'tn.png'), thumbPathSmall, {resize: {width: 240, height: 240}})
const minioClient = new Minio.Client(config.assets.client)
await minioClient.fPutObject(config.assets.bucket, destFile, destination, { 'Content-Type': 'video/mp4' })
await minioClient.fPutObject(config.assets.bucket, thumbFile, thumbPath, { 'Content-Type': 'image/jpeg' })
await minioClient.fPutObject(config.assets.bucket, thumbFileSmall, thumbPathSmall, { 'Content-Type': 'image/jpeg' })
await minioClient.fPutObject(config.assets.bucket, thumbFileMedium, thumbPathMedium, { 'Content-Type': 'image/jpeg' })
const thumbFileMedium = `${baseName}-m.jpg`
const thumbPathMedium = path.join(path.dirname(destination), thumbFileMedium)
await image.convert(path.join(tmpDir, 'tn.png'), thumbPathMedium, {resize: {width: 640, height: 640}})
}
catch (e) {
captureException(e)
errored = true
}
if (!errored) {
const minioClient = new Minio.Client(config.assets.client)
await minioClient.fPutObject(config.assets.bucket, destFile, destination, {'Content-Type': 'video/mp4'})
await minioClient.fPutObject(config.assets.bucket, thumbFile, thumbPath, {'Content-Type': 'image/jpeg'})
await minioClient.fPutObject(config.assets.bucket, thumbFileSmall, thumbPathSmall, {'Content-Type': 'image/jpeg'})
await minioClient.fPutObject(config.assets.bucket, thumbFileMedium, thumbPathMedium, {'Content-Type': 'image/jpeg'})
}
await fs.remove(tmpDir)
......@@ -58,6 +71,7 @@ const concatJob = async function (job) {
if (config.assets.client.port !== 80 && config.assets.client.port !== 443) assetHost += `:${config.assets.client.port}`
assetHost += `/${config.assets.bucket}`
if (errored) return
return {
video: `${assetHost}/${destFile}`,
preview: `${assetHost}/${thumbFile}`
......
......@@ -9,11 +9,14 @@ const
ffmpeg = require('mbjs-media/src/util/ffmpeg'),
image = require('mbjs-media/src/util/image'),
Minio = require('minio'),
{ Assert, ObjectUtil } = require('mbjs-utils')
{ Assert, ObjectUtil } = require('mbjs-utils'),
{ captureException } = require('mbjs-generic-api/src/raven')
const convertJob = async function (job) {
Assert.isType(job.data.source, 'string', 'invalid source')
let errored = false
const uuid = ObjectUtil.uuid4()
const tmpDir = path.join(os.tmpdir(), uuid)
const destFile = `${uuid}.mp4`
......@@ -37,8 +40,10 @@ const convertJob = async function (job) {
job.progress(progress.percent * 0.3)
})
source = tmpdst
} catch (e) {
console.error(e.message)
}
catch (e) {
captureException(e)
errored = true
}
}
try {
......@@ -52,30 +57,40 @@ const convertJob = async function (job) {
job.progress(progress.percent * 0.3)
})
}
} catch (e) {
console.error(e.message)
}
catch (e) {
captureException(e)
errored = true
}
await ffmpegThumb(destination, tmpDir, 1, progress => {
job.progress(60 + progress.percent * 0.3)
})
const thumbFile = `${baseName}.jpg`
const thumbPath = path.join(path.dirname(destination), thumbFile)
await image.convert(path.join(tmpDir, 'tn.png'), thumbPath)
try {
await ffmpegThumb(destination, tmpDir, 1, progress => {
job.progress(60 + progress.percent * 0.3)
})
const thumbFile = `${baseName}.jpg`
const thumbPath = path.join(path.dirname(destination), thumbFile)
await image.convert(path.join(tmpDir, 'tn.png'), thumbPath)
const thumbFileSmall = `${baseName}-s.jpg`
const thumbPathSmall = path.join(path.dirname(destination), thumbFileSmall)
await image.convert(path.join(tmpDir, 'tn.png'), thumbPathSmall, { resize: { width: 240, height: 240 } })
const thumbFileSmall = `${baseName}-s.jpg`
const thumbPathSmall = path.join(path.dirname(destination), thumbFileSmall)
await image.convert(path.join(tmpDir, 'tn.png'), thumbPathSmall, {resize: {width: 240, height: 240}})
const thumbFileMedium = `${baseName}-m.jpg`
const thumbPathMedium = path.join(path.dirname(destination), thumbFileMedium)
await image.convert(path.join(tmpDir, 'tn.png'), thumbPathMedium, { resize: { width: 640, height: 640 } })
const thumbFileMedium = `${baseName}-m.jpg`
const thumbPathMedium = path.join(path.dirname(destination), thumbFileMedium)
await image.convert(path.join(tmpDir, 'tn.png'), thumbPathMedium, {resize: {width: 640, height: 640}})
}
catch (e) {
captureException(e)
errored = true
}
const minioClient = new Minio.Client(config.assets.client)
await minioClient.fPutObject(config.assets.bucket, destFile, destination, { 'Content-Type': 'video/mp4' })
await minioClient.fPutObject(config.assets.bucket, thumbFile, thumbPath, { 'Content-Type': 'image/jpeg' })
await minioClient.fPutObject(config.assets.bucket, thumbFileSmall, thumbPathSmall, { 'Content-Type': 'image/jpeg' })
await minioClient.fPutObject(config.assets.bucket, thumbFileMedium, thumbPathMedium, { 'Content-Type': 'image/jpeg' })
if (!errored) {
const minioClient = new Minio.Client(config.assets.client)
await minioClient.fPutObject(config.assets.bucket, destFile, destination, {'Content-Type': 'video/mp4'})
await minioClient.fPutObject(config.assets.bucket, thumbFile, thumbPath, {'Content-Type': 'image/jpeg'})
await minioClient.fPutObject(config.assets.bucket, thumbFileSmall, thumbPathSmall, {'Content-Type': 'image/jpeg'})
await minioClient.fPutObject(config.assets.bucket, thumbFileMedium, thumbPathMedium, {'Content-Type': 'image/jpeg'})
}
await fs.remove(tmpDir)
......@@ -85,6 +100,7 @@ const convertJob = async function (job) {
if (config.assets.client.port !== 80 && config.assets.client.port !== 443) assetHost += `:${config.assets.client.port}`
assetHost += `/${config.assets.bucket}`
if (errored) return
return {
video: `${assetHost}/${destFile}`,
preview: `${assetHost}/${thumbFile}`
......
......@@ -4,7 +4,8 @@ const
path = require('path'),
{ spawn } = require('child_process'),
ffmpeg = require('mbjs-media/src/util/ffmpeg'),
{ Assert, ObjectUtil } = require('mbjs-utils')
{ Assert, ObjectUtil } = require('mbjs-utils'),
{ captureException } = require('mbjs-generic-api/src/raven')
const extractLTC = function (file) {
return new Promise((resolve, reject) => {
......@@ -22,6 +23,7 @@ const extractLTC = function (file) {
})
ls.on('error', err => {
captureException(err)
reject(err)
})
......@@ -40,28 +42,35 @@ const extractLtcJob = async function (job) {
const destFile = `${uuid}.wav`
const destination = path.join(tmpDir, destFile)
let data
if (job.data.source.indexOf('http') !== 0) {
const stats = await fs.stat(job.data.source)
Assert.ok(stats.isFile() === true, 'invalid source')
}
await fs.ensureDir(tmpDir)
await ffmpeg(job.data.source, destination, {}, progress => {
job.progress(progress.percent * 0.4)
})
const output = await extractLTC(destination)
await fs.remove(tmpDir)
try {
await fs.ensureDir(tmpDir)
await ffmpeg(job.data.source, destination, {}, progress => {
job.progress(progress.percent * 0.4)
})
const output = await extractLTC(destination)
await fs.remove(tmpDir)
const data = output.split('\n').map(line => {
const values = line.split('\t')
if (values.length !== 3) return values
return values.map((val, i) => {
if (i < 2) return parseFloat(val)
if (val.indexOf('No LTC frame found') === 0) return null
return val
data = output.split('\n').map(line => {
const values = line.split('\t')
if (values.length !== 3) return values
return values.map((val, i) => {
if (i < 2) return parseFloat(val)
if (val.indexOf('No LTC frame found') === 0) return null
return val
})
}).filter(entry => {
return entry.length === 3 && entry[2]
})
}).filter(entry => {
return entry.length === 3 && entry[2]
})
}
catch (e) {
captureException(e)
}
job.progress(100)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment