fairy removed from web, makes http request to tpds worker now

This commit is contained in:
Henry Oswald 2015-06-22 22:28:17 +01:00
parent 706c1824f0
commit 2ec925b45e
3 changed files with 35 additions and 19 deletions

View file

@ -4,6 +4,7 @@ path = require('path')
Project = require('../../models/Project').Project
keys = require('../../infrastructure/Keys')
metrics = require("../../infrastructure/Metrics")
request = require("request")
buildPath = (user_id, project_name, filePath)->
projectPath = path.join(project_name, "/", filePath)
@ -11,9 +12,26 @@ buildPath = (user_id, project_name, filePath)->
fullPath = path.join("/user/", "#{user_id}", "/entity/",projectPath)
return fullPath
queue = require('fairy').connect(settings.redis.fairy).queue(keys.queue.web_to_tpds_http_requests)
module.exports =
module.exports = TpdsUpdateSender =
_enqueue: (group, method, job, callback)->
opts =
uri:"http://localhost:3030/enqueue/web_to_tpds_http_requests"
json :
group:group
method:method
job:job
method:"post"
request opts, (err)->
if err?
callback(err)
else
callback()
_addEntity: (options, callback = (err)->)->
getProjectsUsersIds options.project_id, (err, user_id, allUserIds)->
@ -27,9 +45,9 @@ module.exports =
uri : "#{settings.apis.thirdPartyDataStore.url}#{buildPath(user_id, options.project_name, options.path)}"
title: "addFile"
streamOrigin : options.streamOrigin
queue.enqueue options.project_id, "pipeStreamFrom", postOptions, ->
TpdsUpdateSender._enqueue options.project_id, "pipeStreamFrom", postOptions, (err)->
logger.log project_id: options.project_id, user_id:user_id, path: options.path, uri:options.uri, rev:options.rev, "sending file to third party data store queued up for processing"
callback()
callback(err)
addFile : (options, callback = (err)->)->
metrics.inc("tpds.add-file")
@ -64,7 +82,7 @@ module.exports =
user_id : user_id
endPath: endPath
startPath: startPath
queue.enqueue options.project_id, "standardHttpRequest", moveOptions, callback
TpdsUpdateSender._enqueue options.project_id, "standardHttpRequest", moveOptions, callback
deleteEntity : (options, callback = (err)->)->
metrics.inc("tpds.delete-entity")
@ -78,7 +96,7 @@ module.exports =
uri : "#{settings.apis.thirdPartyDataStore.url}#{buildPath(user_id, options.project_name, options.path)}"
title:"deleteEntity"
sl_all_user_ids:JSON.stringify(allUserIds)
queue.enqueue options.project_id, "standardHttpRequest", deleteOptions, callback
TpdsUpdateSender._enqueue options.project_id, "standardHttpRequest", deleteOptions, callback
pollDropboxForUser: (user_id, callback = (err) ->) ->
metrics.inc("tpds.poll-dropbox")
@ -88,7 +106,7 @@ module.exports =
uri:"#{settings.apis.thirdPartyDataStore.url}/user/poll"
json:
user_ids: [user_id]
queue.enqueue "poll-dropbox:#{user_id}", "standardHttpRequest", options, callback
TpdsUpdateSender._enqueue "poll-dropbox:#{user_id}", "standardHttpRequest", options, callback
getProjectsUsersIds = (project_id, callback = (err, owner_id, allUserIds)->)->
Project.findById project_id, "_id owner_ref readOnly_refs collaberator_refs", (err, project)->

View file

@ -17,7 +17,6 @@
"connect-redis": "1.4.5",
"dateformat": "1.0.4-1.2.3",
"express": "3.3.4",
"fairy": "git+https://github.com/sharelatex/fairy.git#cluster",
"http-proxy": "^1.8.1",
"jade": "~1.3.1",
"ldapjs": "^0.7.1",

View file

@ -19,12 +19,11 @@ filestoreUrl = "filestore.sharelatex.com"
describe 'TpdsUpdateSender', ->
beforeEach ->
@requestQueuer = regist:(queue, meth, opts, callback)->
@requestQueuer = (queue, meth, opts, callback)->
project = {owner_ref:user_id,readOnly_refs:[read_only_ref_1], collaberator_refs:[collaberator_ref_1]}
@Project = findById:sinon.stub().callsArgWith(2, null, project)
@docstoreUrl = "docstore.sharelatex.env"
@updateSender = SandboxedModule.require modulePath, requires:
'fairy':{connect:=>{queue:=>@requestQueuer}}
"settings-sharelatex":
siteUrl:siteUrl
httpAuthSiteUrl:httpAuthSiteUrl,
@ -34,17 +33,17 @@ describe 'TpdsUpdateSender', ->
url: filestoreUrl
docstore:
pubUrl: @docstoreUrl
redis:fairy:{}
"logger-sharelatex":{log:->}
'../../models/Project': Project:@Project
'request':->{pipe:->}
describe 'sending updates', ->
it 'ques a post the file with user and file id', (done)->
it 'queues a post the file with user and file id', (done)->
file_id = '4545345'
path = '/some/path/here.jpg'
@requestQueuer.enqueue = (uid, method, job, callback)->
@updateSender._enqueue = (uid, method, job, callback)->
uid.should.equal project_id
job.method.should.equal "post"
job.streamOrigin.should.equal "#{filestoreUrl}/project/#{project_id}/file/#{file_id}"
@ -59,7 +58,7 @@ describe 'TpdsUpdateSender', ->
path = "/some/path/here.tex"
lines = ["line1", "line2", "line3"]
@requestQueuer.enqueue = (uid, method, job, callback)=>
@updateSender._enqueue = (uid, method, job, callback)=>
uid.should.equal project_id
job.method.should.equal "post"
expectedUrl = "#{thirdPartyDataStoreApiUrl}/user/#{user_id}/entity/#{encodeURIComponent(project_name)}#{encodeURIComponent(path)}"
@ -71,7 +70,7 @@ describe 'TpdsUpdateSender', ->
it 'deleting entity', (done)->
path = "/path/here/t.tex"
@requestQueuer.enqueue = (uid, method, job, callback)->
@updateSender._enqueue = (uid, method, job, callback)->
uid.should.equal project_id
job.method.should.equal "DELETE"
expectedUrl = "#{thirdPartyDataStoreApiUrl}/user/#{user_id}/entity/#{encodeURIComponent(project_name)}#{encodeURIComponent(path)}"
@ -83,7 +82,7 @@ describe 'TpdsUpdateSender', ->
it 'moving entity', (done)->
startPath = "staring/here/file.tex"
endPath = "ending/here/file.tex"
@requestQueuer.enqueue = (uid, method, job, callback)->
@updateSender._enqueue = (uid, method, job, callback)->
uid.should.equal project_id
job.method.should.equal "put"
job.uri.should.equal "#{thirdPartyDataStoreApiUrl}/user/#{user_id}/entity"
@ -96,7 +95,7 @@ describe 'TpdsUpdateSender', ->
it 'should be able to rename a project using the move entity func', (done)->
oldProjectName = "/oldProjectName/"
newProjectName = "/newProjectName/"
@requestQueuer.enqueue = (uid, method, job, callback)->
@updateSender._enqueue = (uid, method, job, callback)->
uid.should.equal project_id
job.method.should.equal "put"
job.uri.should.equal "#{thirdPartyDataStoreApiUrl}/user/#{user_id}/entity"
@ -107,9 +106,9 @@ describe 'TpdsUpdateSender', ->
@updateSender.moveEntity {project_id:project_id, project_name:oldProjectName, newProjectName:newProjectName}
it "pollDropboxForUser", (done) ->
@requestQueuer.enqueue = sinon.stub().callsArg(3)
@updateSender._enqueue = sinon.stub().callsArg(3)
@updateSender.pollDropboxForUser user_id, (error) =>
@requestQueuer.enqueue
@updateSender._enqueue
.calledWith(
"poll-dropbox:#{user_id}",
"standardHttpRequest",