Commit 78e1e6d3 authored by Anton's avatar Anton

Add conversion responder

parent d7a066ca
Pipeline #12128 passed with stage
const
config = require('config'),
Queue = require('bull'),
{ DateTime } = require('luxon'),
{ ObjectUtil } = require('mbjs-utils'),
cote = require('cote')
const init = async function () {
const
queue = new Queue('conversions', config.conversions.redisURL),
conversionService = new cote.Responder({ name: 'Conversion Service' })
queue.process(parseInt(config.conversions.concurrency), require('../workers/convert'))
conversionService.on('start', (req, cb) => {
const jobId = ObjectUtil.uuid4()
queue.add(req, { jobId })
cb({ jobId })
})
conversionService.on('status', async (req, cb) => {
const job = await queue.getJob(req.id)
if (!job) return cb(null)
const jobInfo = {
uuid: job.id,
source: job.data.source,
result: job.returnvalue,
failed: typeof job.failedReason !== 'undefined',
attempts: job.attemptsMade,
progress: job.progress,
delay: job.delay,
created: DateTime.fromMillis(job.timestamp).toISO(),
processed: job.processedOn ? DateTime.fromMillis(job.processedOn).toISO() : undefined,
finished: job.finishedOn ? DateTime.fromMillis(job.finishedOn).toISO() : undefined
}
cb(jobInfo)
})
}
init()
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