Commit 20e0d639 authored by Jure's avatar Jure

Merge branch 'improve_job_xsweet' into 'master'

feat(job-xsweet): improve API for GraphQL-based conversion

Closes #453

See merge request !582
parents 99be611c a93bc6d3
Pipeline #13109 passed with stages
in 10 minutes and 27 seconds
......@@ -30,7 +30,6 @@ const resolvers = {
logger.info(pubsubChannel, status)
if (status === 'Conversion complete') {
await waait(1000)
// console.log(job, queueJobId, db)
pubsub.publish(pubsubChannel, {
docxToHTMLJob: {
status: 'Done',
......@@ -86,20 +85,18 @@ const resolvers = {
}
},
},
Query: {
docxToHTMLJob: async (_, { jobId }, context) => {
const job = await db('pgboss.job').whereRaw(
"data->'request'->>'id' = ?",
[jobId],
)
return {
status: 'Final',
html: job[0].data.response.html,
}
},
},
Subscription: {
docxToHTMLJob: {
resolve: async (payload, { jobId }, context) => {
if (payload.docxToHTMLJob && payload.docxToHTMLJob.status === 'Done') {
const job = await db('pgboss.job').whereRaw(
"data->'request'->>'id' = ?",
[payload.docxToHTMLJob.id],
)
payload.docxToHTMLJob.html = job[0].data.response.html
}
return payload.docxToHTMLJob
},
subscribe: async (_, { jobId }, context) => {
const pubsub = await getPubsub()
return pubsub.asyncIterator(`${DOCX_TO_HTML}.${context.user}.${jobId}`)
......@@ -118,10 +115,6 @@ const typeDefs = `
docxToHTMLJob(jobId: String!): DocxToHTMLJob!
}
extend type Query {
docxToHTMLJob(jobId: String!): DocxToHTMLJob!
}
type DocxToHTMLJob {
id: String
status: String!
......
......@@ -108,21 +108,7 @@ describe('XSweet job', () => {
.subscribe({
next: async res => {
if (res.data.docxToHTMLJob.status === 'Done') {
const { body } = await superagent
.post('http://localhost:4000/graphql')
.set('Content-Type', 'application/json')
.set('Authorization', `Bearer ${token}`)
.send({
variables: { jobId: res.data.docxToHTMLJob.id },
query: `query docxToHTMLJob($jobId: String!) {
docxToHTMLJob(jobId: $jobId) {
status
html
}
}`,
})
resolve(body.data.docxToHTMLJob.html)
resolve(res.data.docxToHTMLJob.html)
}
return true
},
......
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