mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 05:53:47 -05:00
Merge pull request #169 from overleaf/bg-record-latexmk-output
record latexmk output
This commit is contained in:
commit
59cd14e160
4 changed files with 71 additions and 5 deletions
|
@ -19,6 +19,7 @@ const Settings = require('settings-sharelatex')
|
||||||
const logger = require('logger-sharelatex')
|
const logger = require('logger-sharelatex')
|
||||||
const Metrics = require('./Metrics')
|
const Metrics = require('./Metrics')
|
||||||
const CommandRunner = require('./CommandRunner')
|
const CommandRunner = require('./CommandRunner')
|
||||||
|
const fs = require('fs')
|
||||||
|
|
||||||
const ProcessTable = {} // table of currently running jobs (pids or docker container names)
|
const ProcessTable = {} // table of currently running jobs (pids or docker container names)
|
||||||
|
|
||||||
|
@ -127,9 +128,36 @@ module.exports = LatexRunner = {
|
||||||
: undefined,
|
: undefined,
|
||||||
x5 => x5[1]
|
x5 => x5[1]
|
||||||
) || 0
|
) || 0
|
||||||
return callback(error, output, stats, timings)
|
// record output files
|
||||||
|
LatexRunner.writeLogOutput(project_id, directory, output, () => {
|
||||||
|
return callback(error, output, stats, timings)
|
||||||
|
})
|
||||||
|
}))
|
||||||
|
},
|
||||||
|
|
||||||
|
writeLogOutput(project_id, directory, output, callback) {
|
||||||
|
if (!output) {
|
||||||
|
return callback()
|
||||||
|
}
|
||||||
|
// internal method for writing non-empty log files
|
||||||
|
function _writeFile(file, content, cb) {
|
||||||
|
if (content && content.length > 0) {
|
||||||
|
fs.writeFile(file, content, (err) => {
|
||||||
|
if (err) {
|
||||||
|
logger.error({ project_id, file }, "error writing log file") // don't fail on error
|
||||||
|
}
|
||||||
|
cb()
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
cb()
|
||||||
}
|
}
|
||||||
))
|
}
|
||||||
|
// write stdout and stderr, ignoring errors
|
||||||
|
_writeFile(Path.join(directory, "output.stdout"), output.stdout, () => {
|
||||||
|
_writeFile(Path.join(directory, "output.stderr"), output.stderr, () => {
|
||||||
|
callback()
|
||||||
|
})
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
killLatex(project_id, callback) {
|
killLatex(project_id, callback) {
|
||||||
|
|
|
@ -231,7 +231,9 @@ module.exports = ResourceWriter = {
|
||||||
path === 'output.pdf' ||
|
path === 'output.pdf' ||
|
||||||
path === 'output.dvi' ||
|
path === 'output.dvi' ||
|
||||||
path === 'output.log' ||
|
path === 'output.log' ||
|
||||||
path === 'output.xdv'
|
path === 'output.xdv' ||
|
||||||
|
path === 'output.stdout' ||
|
||||||
|
path === 'output.stderr'
|
||||||
) {
|
) {
|
||||||
should_delete = true
|
should_delete = true
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,10 @@ describe('LatexRunner', function() {
|
||||||
done() {}
|
done() {}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
'./CommandRunner': (this.CommandRunner = {})
|
'./CommandRunner': (this.CommandRunner = {}),
|
||||||
|
'fs': (this.fs = {
|
||||||
|
writeFile: sinon.stub().callsArg(2)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -83,6 +86,21 @@ describe('LatexRunner', function() {
|
||||||
)
|
)
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should record the stdout and stderr', function () {
|
||||||
|
this.fs.writeFile
|
||||||
|
.calledWith(
|
||||||
|
this.directory + '/' + 'output.stdout',
|
||||||
|
"this is stdout"
|
||||||
|
)
|
||||||
|
.should.equal(true)
|
||||||
|
this.fs.writeFile
|
||||||
|
.calledWith(
|
||||||
|
this.directory + '/' + 'output.stderr',
|
||||||
|
"this is stderr"
|
||||||
|
)
|
||||||
|
.should.equal(true)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('with an .Rtex main file', function() {
|
describe('with an .Rtex main file', function() {
|
||||||
|
|
|
@ -230,6 +230,12 @@ describe('ResourceWriter', function() {
|
||||||
{
|
{
|
||||||
path: '_markdown_main/30893013dec5d869a415610079774c2f.md.tex',
|
path: '_markdown_main/30893013dec5d869a415610079774c2f.md.tex',
|
||||||
type: 'tex'
|
type: 'tex'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'output.stdout'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'output.stderr'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
this.resources = 'mock-resources'
|
this.resources = 'mock-resources'
|
||||||
|
@ -256,7 +262,19 @@ describe('ResourceWriter', function() {
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should delete the extra files', function() {
|
it('should delete the stdout log file', function () {
|
||||||
|
return this.ResourceWriter._deleteFileIfNotDirectory
|
||||||
|
.calledWith(path.join(this.basePath, 'output.stdout'))
|
||||||
|
.should.equal(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should delete the stderr log file', function () {
|
||||||
|
return this.ResourceWriter._deleteFileIfNotDirectory
|
||||||
|
.calledWith(path.join(this.basePath, 'output.stderr'))
|
||||||
|
.should.equal(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should delete the extra files', function () {
|
||||||
return this.ResourceWriter._deleteFileIfNotDirectory
|
return this.ResourceWriter._deleteFileIfNotDirectory
|
||||||
.calledWith(path.join(this.basePath, 'extra/file.tex'))
|
.calledWith(path.join(this.basePath, 'extra/file.tex'))
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
|
|
Loading…
Reference in a new issue