From f99a6dc39b3017642c3369a643a2827da5249372 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Tue, 18 Feb 2014 17:43:21 +0000 Subject: [PATCH] changed file converted to use child process with nice --- .../filestore/app/coffee/FileConverter.coffee | 16 +++++----- .../filestore/app/coffee/s3Wrapper.coffee | 2 ++ .../config/settings.development.coffee | 1 - services/filestore/package.json | 4 +-- .../unit/coffee/FileConverterTests.coffee | 30 +++++++++---------- 5 files changed, 25 insertions(+), 28 deletions(-) diff --git a/services/filestore/app/coffee/FileConverter.coffee b/services/filestore/app/coffee/FileConverter.coffee index 11f405361c..63672c3872 100644 --- a/services/filestore/app/coffee/FileConverter.coffee +++ b/services/filestore/app/coffee/FileConverter.coffee @@ -2,7 +2,7 @@ easyimage = require("easyimage") _ = require("underscore") metrics = require("./metrics") logger = require("logger-sharelatex") - +exec = require('child_process').exec approvedFormats = ["png"] module.exports = @@ -15,10 +15,8 @@ module.exports = if !_.include approvedFormats, requestedFormat err = new Error("invalid format requested") return callback err - args = - src: sourcePath - dst: destPath - easyimage.convert args, (err)-> + args = "nice convert -flatten -density 300 #{sourcePath} #{destPath}" + exec args, (err, stdout, stderr)-> timer.done() callback(err, destPath) @@ -31,8 +29,8 @@ module.exports = dst: destPath width: 424 height: 300 - args = "convert -flatten -background white -resize 300x -density 300 #{sourcePath} #{destPath}" - easyimage.exec args, (err)-> + args = "nice convert -flatten -background white -resize 300x -density 300 #{sourcePath} #{destPath}" + exec args, (err, stdout, stderr)-> callback(err, destPath) preview: (sourcePath, callback)-> @@ -44,6 +42,6 @@ module.exports = dst: destPath width: 600 height: 849 - args = "convert -flatten -background white -resize 600x -density 300 #{sourcePath} #{destPath}" - easyimage.exec args, (err)-> + args = "nice convert -flatten -background white -resize 600x -density 300 #{sourcePath} #{destPath}" + exec args, (err, stdout, stderr)-> callback(err, destPath) diff --git a/services/filestore/app/coffee/s3Wrapper.coffee b/services/filestore/app/coffee/s3Wrapper.coffee index d9ef3dea55..bff18f90c7 100644 --- a/services/filestore/app/coffee/s3Wrapper.coffee +++ b/services/filestore/app/coffee/s3Wrapper.coffee @@ -99,6 +99,8 @@ module.exports = request options, (err, res)-> if err? 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 logger.log bucketName:bucketName, key:key, exists:exists, "checked if file exsists in s3" callback(err, exists) diff --git a/services/filestore/config/settings.development.coffee b/services/filestore/config/settings.development.coffee index 2fa32e622e..3f390837d8 100644 --- a/services/filestore/config/settings.development.coffee +++ b/services/filestore/config/settings.development.coffee @@ -13,7 +13,6 @@ module.exports = user_files: "" template_files: "" - # Filestore health check # ---------------------- # Project and file details to check in filestore when calling /health_check diff --git a/services/filestore/package.json b/services/filestore/package.json index 02a7656538..a10bf95b87 100644 --- a/services/filestore/package.json +++ b/services/filestore/package.json @@ -10,12 +10,12 @@ "knox": "~0.8.8", "node-uuid": "~1.4.1", "underscore": "~1.5.2", - "easyimage": "~0.1.6", "express": "~3.4.8", "longjohn": "~0.2.2", "async": "~0.2.10", "pngcrush": "0.0.3", - "stream-buffers": "~0.2.5" + "stream-buffers": "~0.2.5", + "node-transloadit": "0.0.4" }, "devDependencies": { "sinon": "", diff --git a/services/filestore/test/unit/coffee/FileConverterTests.coffee b/services/filestore/test/unit/coffee/FileConverterTests.coffee index bfdec86813..41f9d5090d 100644 --- a/services/filestore/test/unit/coffee/FileConverterTests.coffee +++ b/services/filestore/test/unit/coffee/FileConverterTests.coffee @@ -13,8 +13,11 @@ describe "FileConverter", -> @easyimage = convert:sinon.stub() exec: sinon.stub() + @child_process = + exec : sinon.stub() @converter = SandboxedModule.require modulePath, requires: "easyimage":@easyimage + 'child_process': @child_process "logger-sharelatex": log:-> err:-> @@ -26,48 +29,43 @@ describe "FileConverter", -> describe "convert", -> it "should convert the source to the requested format", (done)-> - @easyimage.convert.callsArgWith(1) + @child_process.exec.callsArgWith(1) @converter.convert @sourcePath, @format, (err)=> - args = @easyimage.convert.args[0][0] - args.src.should.equal @sourcePath+"[0]" - args.dst.should.equal "#{@sourcePath}.#{@format}" + args = @child_process.exec.args[0][0] + args.indexOf(@sourcePath).should.not.equal -1 + args.indexOf(@format).should.not.equal -1 done() - it "should return the dest path", (done)-> - @easyimage.convert.callsArgWith(1) + @child_process.exec.callsArgWith(1) @converter.convert @sourcePath, @format, (err, destPath)=> destPath.should.equal "#{@sourcePath}.#{@format}" 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)=> err.should.equal @error done() it "should not accapt an non aproved format", (done)-> - @easyimage.convert.callsArgWith(1) + @child_process.exec.callsArgWith(1) @converter.convert @sourcePath, "ahhhhh", (err)=> expect(err).to.exist done() - describe "thumbnail", -> it "should call easy image resize with args", (done)-> - @easyimage.exec.callsArgWith(1) + @child_process.exec.callsArgWith(1) @converter.thumbnail @sourcePath, (err)=> - args = @easyimage.exec.args[0][0] + args = @child_process.exec.args[0][0] args.indexOf(@sourcePath).should.not.equal -1 done() - it "should compress the png", ()-> - - describe "preview", -> it "should call easy image resize with args", (done)-> - @easyimage.exec.callsArgWith(1) + @child_process.exec.callsArgWith(1) @converter.preview @sourcePath, (err)=> - args = @easyimage.exec.args[0][0] + args = @child_process.exec.args[0][0] args.indexOf(@sourcePath).should.not.equal -1 done()