|
|
@@ -1,4 +1,4 @@
|
|
|
-import request from 'request'
|
|
|
+import { fetchJson } from '@overleaf/fetch-utils'
|
|
|
import Settings from '@overleaf/settings'
|
|
|
|
|
|
const buildUrl = path =>
|
|
|
@@ -7,17 +7,29 @@ const buildUrl = path =>
|
|
|
const url = buildUrl(`project/smoketest-${process.pid}/compile`)
|
|
|
|
|
|
export default {
|
|
|
- sendNewResult(res) {
|
|
|
- this._run(error => this._sendResponse(res, error))
|
|
|
+ async sendNewResult(res) {
|
|
|
+ let error
|
|
|
+ try {
|
|
|
+ await this._run()
|
|
|
+ } catch (err) {
|
|
|
+ error = err
|
|
|
+ }
|
|
|
+
|
|
|
+ this._sendResponse(res, error)
|
|
|
},
|
|
|
sendLastResult(res) {
|
|
|
this._sendResponse(res, this._lastError)
|
|
|
},
|
|
|
triggerRun(cb) {
|
|
|
- this._run(error => {
|
|
|
- this._lastError = error
|
|
|
- cb(error)
|
|
|
- })
|
|
|
+ this._run()
|
|
|
+ .then(() => {
|
|
|
+ this._lastError = null
|
|
|
+ cb()
|
|
|
+ })
|
|
|
+ .catch(error => {
|
|
|
+ this._lastError = error
|
|
|
+ cb(error)
|
|
|
+ })
|
|
|
},
|
|
|
lastRunSuccessful() {
|
|
|
return this._lastError == null
|
|
|
@@ -36,19 +48,18 @@ export default {
|
|
|
res.contentType('text/plain')
|
|
|
res.status(code).send(body)
|
|
|
},
|
|
|
- _run(done) {
|
|
|
- request.post(
|
|
|
- {
|
|
|
- url,
|
|
|
- json: {
|
|
|
- compile: {
|
|
|
- options: {
|
|
|
- metricsPath: 'health-check',
|
|
|
- },
|
|
|
- resources: [
|
|
|
- {
|
|
|
- path: 'main.tex',
|
|
|
- content: `\
|
|
|
+ async _run() {
|
|
|
+ const body = await fetchJson(url, {
|
|
|
+ method: 'POST',
|
|
|
+ json: {
|
|
|
+ compile: {
|
|
|
+ options: {
|
|
|
+ metricsPath: 'health-check',
|
|
|
+ },
|
|
|
+ resources: [
|
|
|
+ {
|
|
|
+ path: 'main.tex',
|
|
|
+ content: `\
|
|
|
% Membrane-like surface
|
|
|
% Author: Yotam Avital
|
|
|
\\documentclass{article}
|
|
|
@@ -102,28 +113,24 @@ date
|
|
|
|
|
|
\\end{document}\
|
|
|
`,
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
+ },
|
|
|
+ ],
|
|
|
},
|
|
|
},
|
|
|
- (error, response, body) => {
|
|
|
- if (error) return done(error)
|
|
|
- if (!body || !body.compile || !body.compile.outputFiles) {
|
|
|
- return done(new Error('response payload incomplete'))
|
|
|
- }
|
|
|
+ })
|
|
|
|
|
|
- let pdfFound = false
|
|
|
- let logFound = false
|
|
|
- for (const file of body.compile.outputFiles) {
|
|
|
- if (file.type === 'pdf') pdfFound = true
|
|
|
- if (file.type === 'log') logFound = true
|
|
|
- }
|
|
|
+ if (!body || !body.compile || !body.compile.outputFiles) {
|
|
|
+ throw new Error('response payload incomplete')
|
|
|
+ }
|
|
|
+
|
|
|
+ let pdfFound = false
|
|
|
+ let logFound = false
|
|
|
+ for (const file of body.compile.outputFiles) {
|
|
|
+ if (file.type === 'pdf') pdfFound = true
|
|
|
+ if (file.type === 'log') logFound = true
|
|
|
+ }
|
|
|
|
|
|
- if (!pdfFound) return done(new Error('no pdf returned'))
|
|
|
- if (!logFound) return done(new Error('no log returned'))
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
+ if (!pdfFound) throw new Error('no pdf returned')
|
|
|
+ if (!logFound) throw new Error('no log returned')
|
|
|
},
|
|
|
}
|