Commit d9ee21f9 authored by Jure's avatar Jure

fix(job-xsweet): improve error and stream handling

parent a93bc6d3
Pipeline #13116 passed with stages
in 12 minutes and 13 seconds
......@@ -17,7 +17,7 @@ RUN yarn
# Download XSweet
RUN wget https://gitlab.coko.foundation/XSweet/XSweet/repository/archive.zip?ref=master -O xsweet.zip; unzip xsweet.zip; rm xsweet.zip
RUN wget https://gitlab.coko.foundation/XSweet/editoria_typescript/repository/archive.zip?ref=master -O typescript.zip; unzip typescript.zip; rm typescript.zip
RUN wget https://gitlab.coko.foundation/XSweet/HTMLevator/repository/archive.zip?ref=eeef394426f7db7647d992aafdda1b677b35b7ae -O htmlevator.zip; unzip htmlevator.zip; rm htmlevator.zip
RUN wget https://gitlab.coko.foundation/XSweet/HTMLevator/repository/archive.zip?ref=master -O htmlevator.zip; unzip htmlevator.zip; rm htmlevator.zip
# Download Saxon
RUN wget "https://downloads.sourceforge.net/project/saxon/Saxon-HE/9.9/SaxonHE9-9-1-1J.zip" -O saxon.zip; unzip saxon.zip -d saxon; rm saxon.zip
......
......@@ -30,7 +30,22 @@ XMLTOHTML5="${XSWEET}/applications/html-polish/html5-serialize.xsl"
$saxonHE -xsl:$PIPELINE -s:$TEMP/word/document.xml -o:$TEMP/outputs/PIPELINED.xhtml
echo Made PIPELINED.xhtml
if [ $? -eq 0 ]
then
echo "Made PIPELINED.xhtml"
else
echo "There was an error converting the document." >&2
exit 1
fi
$saxonHE -xsl:$XMLTOHTML5 -s:$TEMP/outputs/PIPELINED.xhtml -o:$TEMP/outputs/HTML5.html
echo Made HTML5.html
\ No newline at end of file
if [ $? -eq 0 ]
then
echo "Made HTML5.html"
exit 0
else
echo "There was an error converting the document." >&2
exit 1
fi
\ No newline at end of file
......@@ -18,7 +18,7 @@ const resolvers = {
const pubsub = await getPubsub()
const { createReadStream, filename } = await file
const stream = await createReadStream()
const stream = createReadStream()
const jobId = crypto.randomBytes(3).toString('hex')
const pubsubChannel = `${DOCX_TO_HTML}.${context.user}.${jobId}`
......@@ -48,34 +48,38 @@ const resolvers = {
const chunks = []
stream.on('data', chunk => {
chunks.push(chunk)
})
stream.on('end', () => {
pubsub.publish(pubsubChannel, {
docxToHTMLJob: {
status: 'File uploaded and conversion job created',
id: jobId,
},
await new Promise((resolve, reject) => {
stream.on('data', chunk => {
chunks.push(chunk)
})
const result = Buffer.concat(chunks)
jobQueue
.publish(`xsweetGraphQL`, {
docx: {
name: filename,
data: result.toString('base64'),
stream.on('end', () => {
pubsub.publish(pubsubChannel, {
docxToHTMLJob: {
status: 'File uploaded and conversion job created',
id: jobId,
},
pubsubChannel,
})
.then(id => (queueJobId = id))
})
stream.on('error', e => {
pubsub.publish(pubsubChannel, {
status: e,
const result = Buffer.concat(chunks)
jobQueue
.publish(`xsweetGraphQL`, {
docx: {
name: filename,
data: result.toString('base64'),
},
pubsubChannel,
})
.then(id => (queueJobId = id))
resolve()
})
stream.on('error', e => {
pubsub.publish(pubsubChannel, {
status: e,
})
reject(e)
})
})
......
......@@ -71,7 +71,6 @@ const xsweetHandler = enablePubsub => async job => {
}
execSync(`bash ${path.resolve(__dirname, 'execute_chain.sh')} ${tmpDir}`)
const html = fs.readFileSync(
path.join(tmpDir, 'outputs', 'HTML5.html'),
'utf8',
......@@ -103,7 +102,7 @@ const xsweetHandler = enablePubsub => async job => {
})
}
return { html: null }
throw new Error('Conversion error')
}
}
......
......@@ -33,7 +33,7 @@ describe('XSweet job', () => {
await destroy()
await server.close()
setImmediate(() => server.emit('close'))
await wait(500)
await wait(1000)
done()
})
......@@ -107,6 +107,9 @@ describe('XSweet job', () => {
})
.subscribe({
next: async res => {
if (res.data.docxToHTMLJob.status === 'Conversion error') {
reject(res.data.docxToHTMLJob.status)
}
if (res.data.docxToHTMLJob.status === 'Done') {
resolve(res.data.docxToHTMLJob.html)
}
......
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