changed file converted to use child process with nice

This commit is contained in:
Henry Oswald 2014-02-18 17:43:21 +00:00
parent 1ff5a5adb8
commit f99a6dc39b
5 changed files with 25 additions and 28 deletions

View file

@ -2,7 +2,7 @@ easyimage = require("easyimage")
_ = require("underscore") _ = require("underscore")
metrics = require("./metrics") metrics = require("./metrics")
logger = require("logger-sharelatex") logger = require("logger-sharelatex")
exec = require('child_process').exec
approvedFormats = ["png"] approvedFormats = ["png"]
module.exports = module.exports =
@ -15,10 +15,8 @@ module.exports =
if !_.include approvedFormats, requestedFormat if !_.include approvedFormats, requestedFormat
err = new Error("invalid format requested") err = new Error("invalid format requested")
return callback err return callback err
args = args = "nice convert -flatten -density 300 #{sourcePath} #{destPath}"
src: sourcePath exec args, (err, stdout, stderr)->
dst: destPath
easyimage.convert args, (err)->
timer.done() timer.done()
callback(err, destPath) callback(err, destPath)
@ -31,8 +29,8 @@ module.exports =
dst: destPath dst: destPath
width: 424 width: 424
height: 300 height: 300
args = "convert -flatten -background white -resize 300x -density 300 #{sourcePath} #{destPath}" args = "nice convert -flatten -background white -resize 300x -density 300 #{sourcePath} #{destPath}"
easyimage.exec args, (err)-> exec args, (err, stdout, stderr)->
callback(err, destPath) callback(err, destPath)
preview: (sourcePath, callback)-> preview: (sourcePath, callback)->
@ -44,6 +42,6 @@ module.exports =
dst: destPath dst: destPath
width: 600 width: 600
height: 849 height: 849
args = "convert -flatten -background white -resize 600x -density 300 #{sourcePath} #{destPath}" args = "nice convert -flatten -background white -resize 600x -density 300 #{sourcePath} #{destPath}"
easyimage.exec args, (err)-> exec args, (err, stdout, stderr)->
callback(err, destPath) callback(err, destPath)

View file

@ -99,6 +99,8 @@ module.exports =
request options, (err, res)-> request options, (err, res)->
if err? if err?
logger.err err:err, res:res, bucketName:bucketName, key:key, "something went wrong copying file in aws" logger.err err:err, res:res, bucketName:bucketName, key:key, "something went wrong copying file in aws"
if !res?
logger.err err:err, res:res, bucketName:bucketName, key:key, "no response object returned when checking if file exists"
exists = res.statusCode == 200 exists = res.statusCode == 200
logger.log bucketName:bucketName, key:key, exists:exists, "checked if file exsists in s3" logger.log bucketName:bucketName, key:key, exists:exists, "checked if file exsists in s3"
callback(err, exists) callback(err, exists)

View file

@ -13,7 +13,6 @@ module.exports =
user_files: "" user_files: ""
template_files: "" template_files: ""
# Filestore health check # Filestore health check
# ---------------------- # ----------------------
# Project and file details to check in filestore when calling /health_check # Project and file details to check in filestore when calling /health_check

View file

@ -10,12 +10,12 @@
"knox": "~0.8.8", "knox": "~0.8.8",
"node-uuid": "~1.4.1", "node-uuid": "~1.4.1",
"underscore": "~1.5.2", "underscore": "~1.5.2",
"easyimage": "~0.1.6",
"express": "~3.4.8", "express": "~3.4.8",
"longjohn": "~0.2.2", "longjohn": "~0.2.2",
"async": "~0.2.10", "async": "~0.2.10",
"pngcrush": "0.0.3", "pngcrush": "0.0.3",
"stream-buffers": "~0.2.5" "stream-buffers": "~0.2.5",
"node-transloadit": "0.0.4"
}, },
"devDependencies": { "devDependencies": {
"sinon": "", "sinon": "",

View file

@ -13,8 +13,11 @@ describe "FileConverter", ->
@easyimage = @easyimage =
convert:sinon.stub() convert:sinon.stub()
exec: sinon.stub() exec: sinon.stub()
@child_process =
exec : sinon.stub()
@converter = SandboxedModule.require modulePath, requires: @converter = SandboxedModule.require modulePath, requires:
"easyimage":@easyimage "easyimage":@easyimage
'child_process': @child_process
"logger-sharelatex": "logger-sharelatex":
log:-> log:->
err:-> err:->
@ -26,48 +29,43 @@ describe "FileConverter", ->
describe "convert", -> describe "convert", ->
it "should convert the source to the requested format", (done)-> it "should convert the source to the requested format", (done)->
@easyimage.convert.callsArgWith(1) @child_process.exec.callsArgWith(1)
@converter.convert @sourcePath, @format, (err)=> @converter.convert @sourcePath, @format, (err)=>
args = @easyimage.convert.args[0][0] args = @child_process.exec.args[0][0]
args.src.should.equal @sourcePath+"[0]" args.indexOf(@sourcePath).should.not.equal -1
args.dst.should.equal "#{@sourcePath}.#{@format}" args.indexOf(@format).should.not.equal -1
done() done()
it "should return the dest path", (done)-> it "should return the dest path", (done)->
@easyimage.convert.callsArgWith(1) @child_process.exec.callsArgWith(1)
@converter.convert @sourcePath, @format, (err, destPath)=> @converter.convert @sourcePath, @format, (err, destPath)=>
destPath.should.equal "#{@sourcePath}.#{@format}" destPath.should.equal "#{@sourcePath}.#{@format}"
done() done()
it "should return the error from convert", (done)-> it "should return the error from convert", (done)->
@easyimage.convert.callsArgWith(1, @error) @child_process.exec.callsArgWith(1, @error)
@converter.convert @sourcePath, @format, (err)=> @converter.convert @sourcePath, @format, (err)=>
err.should.equal @error err.should.equal @error
done() done()
it "should not accapt an non aproved format", (done)-> it "should not accapt an non aproved format", (done)->
@easyimage.convert.callsArgWith(1) @child_process.exec.callsArgWith(1)
@converter.convert @sourcePath, "ahhhhh", (err)=> @converter.convert @sourcePath, "ahhhhh", (err)=>
expect(err).to.exist expect(err).to.exist
done() done()
describe "thumbnail", -> describe "thumbnail", ->
it "should call easy image resize with args", (done)-> it "should call easy image resize with args", (done)->
@easyimage.exec.callsArgWith(1) @child_process.exec.callsArgWith(1)
@converter.thumbnail @sourcePath, (err)=> @converter.thumbnail @sourcePath, (err)=>
args = @easyimage.exec.args[0][0] args = @child_process.exec.args[0][0]
args.indexOf(@sourcePath).should.not.equal -1 args.indexOf(@sourcePath).should.not.equal -1
done() done()
it "should compress the png", ()->
describe "preview", -> describe "preview", ->
it "should call easy image resize with args", (done)-> it "should call easy image resize with args", (done)->
@easyimage.exec.callsArgWith(1) @child_process.exec.callsArgWith(1)
@converter.preview @sourcePath, (err)=> @converter.preview @sourcePath, (err)=>
args = @easyimage.exec.args[0][0] args = @child_process.exec.args[0][0]
args.indexOf(@sourcePath).should.not.equal -1 args.indexOf(@sourcePath).should.not.equal -1
done() done()