Commit 918ac54e authored by Jure's avatar Jure

Merge branch 'improve_job_xsweet' into 'master'

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

See merge request !584
parents f0fe368a d9ee21f9
Pipeline #13117 passed with stages
in 11 minutes and 49 seconds
...@@ -17,7 +17,7 @@ RUN yarn ...@@ -17,7 +17,7 @@ RUN yarn
# Download XSweet # 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/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/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 # 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 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" ...@@ -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 $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 $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 = { ...@@ -18,7 +18,7 @@ const resolvers = {
const pubsub = await getPubsub() const pubsub = await getPubsub()
const { createReadStream, filename } = await file const { createReadStream, filename } = await file
const stream = await createReadStream() const stream = createReadStream()
const jobId = crypto.randomBytes(3).toString('hex') const jobId = crypto.randomBytes(3).toString('hex')
const pubsubChannel = `${DOCX_TO_HTML}.${context.user}.${jobId}` const pubsubChannel = `${DOCX_TO_HTML}.${context.user}.${jobId}`
...@@ -48,34 +48,38 @@ const resolvers = { ...@@ -48,34 +48,38 @@ const resolvers = {
const chunks = [] const chunks = []
stream.on('data', chunk => { await new Promise((resolve, reject) => {
chunks.push(chunk) stream.on('data', chunk => {
}) chunks.push(chunk)
stream.on('end', () => {
pubsub.publish(pubsubChannel, {
docxToHTMLJob: {
status: 'File uploaded and conversion job created',
id: jobId,
},
}) })
const result = Buffer.concat(chunks) stream.on('end', () => {
pubsub.publish(pubsubChannel, {
jobQueue docxToHTMLJob: {
.publish(`xsweetGraphQL`, { status: 'File uploaded and conversion job created',
docx: { id: jobId,
name: filename,
data: result.toString('base64'),
}, },
pubsubChannel,
}) })
.then(id => (queueJobId = id))
})
stream.on('error', e => { const result = Buffer.concat(chunks)
pubsub.publish(pubsubChannel, {
status: e, 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 => { ...@@ -71,7 +71,6 @@ const xsweetHandler = enablePubsub => async job => {
} }
execSync(`bash ${path.resolve(__dirname, 'execute_chain.sh')} ${tmpDir}`) execSync(`bash ${path.resolve(__dirname, 'execute_chain.sh')} ${tmpDir}`)
const html = fs.readFileSync( const html = fs.readFileSync(
path.join(tmpDir, 'outputs', 'HTML5.html'), path.join(tmpDir, 'outputs', 'HTML5.html'),
'utf8', 'utf8',
...@@ -103,7 +102,7 @@ const xsweetHandler = enablePubsub => async job => { ...@@ -103,7 +102,7 @@ const xsweetHandler = enablePubsub => async job => {
}) })
} }
return { html: null } throw new Error('Conversion error')
} }
} }
......
...@@ -33,7 +33,7 @@ describe('XSweet job', () => { ...@@ -33,7 +33,7 @@ describe('XSweet job', () => {
await destroy() await destroy()
await server.close() await server.close()
setImmediate(() => server.emit('close')) setImmediate(() => server.emit('close'))
await wait(500) await wait(1000)
done() done()
}) })
...@@ -107,6 +107,9 @@ describe('XSweet job', () => { ...@@ -107,6 +107,9 @@ describe('XSweet job', () => {
}) })
.subscribe({ .subscribe({
next: async res => { next: async res => {
if (res.data.docxToHTMLJob.status === 'Conversion error') {
reject(res.data.docxToHTMLJob.status)
}
if (res.data.docxToHTMLJob.status === 'Done') { if (res.data.docxToHTMLJob.status === 'Done') {
resolve(res.data.docxToHTMLJob.html) 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