This commit is contained in:
Henry Oswald 2014-08-21 13:03:54 +01:00
commit 4a19d6731a
6 changed files with 0 additions and 137 deletions

View file

@ -1,21 +0,0 @@
settings = require('settings-sharelatex')
TpdsPollingBackgroundTasks = require("./app/js/Features/ThirdPartyDataStore/TpdsPollingBackgroundTasks")
time =
oneHour : 60 * 60 * 1000
fifteenMinutes : 15 * 60 * 1000
thirtySeconds : 30 * 1000
betweenThirtyAndFiveHundredSeconds: =>
random = Math.floor(Math.random() * 500) * 1000
if random < time.thirtySeconds
return time.betweenThirtyAndFiveHundredSeconds()
else
return random
runPeriodically = (funcToRun, periodLength)->
recursiveReference = ->
funcToRun ->
setTimeout recursiveReference, periodLength
setTimeout recursiveReference, 0
runPeriodically ((cb) -> TpdsPollingBackgroundTasks.pollUsersWithDropbox(cb)), time.fifteenMinutes

View file

@ -15,7 +15,6 @@ EditorRealTimeController = require("./EditorRealTimeController")
TrackChangesManager = require("../TrackChanges/TrackChangesManager")
settings = require('settings-sharelatex')
slReqIdHelper = require('soa-req-id')
tpdsPollingBackgroundTasks = require('../ThirdPartyDataStore/TpdsPollingBackgroundTasks')
async = require('async')
ConnectedUsersManager = require("../ConnectedUsers/ConnectedUsersManager")
_ = require('underscore')
@ -230,10 +229,6 @@ module.exports = EditorController =
EditorRealTimeController.emitToRoom(project_id, 'projectRenamedOrDeletedByExternalSource')
callback()
getLastTimePollHappned: (callback)->
logger.log "getting last time a poll happened in dropbox"
tpdsPollingBackgroundTasks.getLastTimePollHappned callback
updateProjectDescription: (project_id, description, callback = ->)->
logger.log project_id:project_id, description:description, "updating project description"
ProjectDetailsHandler.setProjectDescription project_id, description, (err)->

View file

@ -1,38 +0,0 @@
User = require('../../models/User').User
settings = require('settings-sharelatex')
request = require "request"
logger = require('logger-sharelatex')
redis = require('redis')
rclient = redis.createClient(settings.redis.web.port, settings.redis.web.host)
rclient.auth(settings.redis.web.password)
LAST_TIME_POLL_HAPPEND_KEY = "LAST_TIME_POLL_HAPPEND_KEY"
self = module.exports =
pollUsersWithDropbox: (callback)->
self._getUserIdsWithDropbox (err, user_ids)=>
logger.log user_ids:user_ids, userCount:user_ids.length, "telling tpds to poll users with dropbox"
self._markPollHappened()
self._sendToTpds user_ids, callback
_sendToTpds : (user_ids, callback)->
if user_ids.length > 0
request.post {uri:"#{settings.apis.thirdPartyDataStore.url}/user/poll", json:{user_ids:user_ids}}, callback
else if callback?
callback()
_getUserIdsWithDropbox: (callback)->
User.find {"dropbox.access_token.oauth_token_secret":{"$exists":true}, "features.dropbox":true}, "_id", (err, users)->
ids = users.map (user)->
return user._id+""
callback err, ids
_markPollHappened: (callback)->
rclient.set LAST_TIME_POLL_HAPPEND_KEY, new Date().getTime(), callback
getLastTimePollHappned: (callback = (err, lastTimePollHappened)->)->
rclient.get LAST_TIME_POLL_HAPPEND_KEY, (err, time)->
logger.log lastTimePollHappened:time, "got last time a poll happend to dropbox"
callback(err, time)

View file

@ -300,9 +300,6 @@ module.exports = class Router
AuthorizationManager.ensureClientCanEditProject client, (error, project_id) =>
EditorController.updateProjectDescription project_id, description, callback
client.on "getLastTimePollHappned", (callback)->
EditorController.getLastTimePollHappned(callback)
client.on "getPublishedDetails", (user_id, callback)->
AuthorizationManager.ensureClientCanViewProject client, (error, project_id) =>
TemplatesController.getTemplateDetails user_id, project_id, callback

View file

@ -45,7 +45,6 @@ describe "EditorController", ->
redis: web:{}
@dropboxProjectLinker = {}
@callback = sinon.stub()
@TpdsPollingBackgroundTasks = {}
@ProjectDetailsHandler =
setProjectDescription:sinon.stub()
@CollaboratorsHandler =
@ -72,7 +71,6 @@ describe "EditorController", ->
'../../models/Project' : Project: @Project
"settings-sharelatex":@settings
'../Dropbox/DropboxProjectLinker':@dropboxProjectLinker
'../ThirdPartyDataStore/TpdsPollingBackgroundTasks':@TpdsPollingBackgroundTasks
'./EditorRealTimeController':@EditorRealTimeController = {}
"../../infrastructure/Metrics": @Metrics = { inc: sinon.stub() }
"../TrackChanges/TrackChangesManager": @TrackChangesManager = {}
@ -624,14 +622,6 @@ describe "EditorController", ->
.should.equal true
done()
describe "gettingTimeOfLastTpdsPoll", ->
it "should ask the tpdsPollingBackgroundTask", (done)->
date = new Date()
@TpdsPollingBackgroundTasks.getLastTimePollHappned = sinon.stub().callsArgWith(0, null, date)
@EditorController.getLastTimePollHappned (err, lastTimePollHappened)->
lastTimePollHappened.should.equal date
done()
describe "updateProjectDescription", ->
beforeEach ->
@description = "new description"

View file

@ -1,60 +0,0 @@
SandboxedModule = require('sandboxed-module')
assert = require('assert')
require('chai').should()
sinon = require('sinon')
modulePath = require('path').join __dirname, '../../../../app/js/Features/ThirdPartyDataStore/TpdsPollingBackgroundTasks.js'
describe 'third party data store', ->
beforeEach ->
@request = post:sinon.stub().callsArgWith(1, null)
@userModel = {}
@redis = auth:->
@settings =
apis:
thirdPartyDataStore: {url: "http://tpds.com"}
redis:
web:{}
@poller = SandboxedModule.require modulePath, requires:
"redis":createClient:=>@redis
"settings-sharelatex":@settings
"request":@request
'../../models/User':User:@userModel
'logger-sharelatex':
log:->
err:->
describe "polling user have dropbox", ->
it 'should find the users with project', (done)->
users = [{_id:"1234"}, {_id:"213oija"}, {_id:"2iojdsjoidsk"}]
@userModel.find = sinon.stub().callsArgWith(2, null, users)
@poller._sendToTpds = sinon.stub().callsArgWith(1, null)
@poller._markPollHappened = sinon.stub()
@poller.pollUsersWithDropbox (err)=>
@userModel.find.calledWith({"dropbox.access_token.oauth_token_secret":{"$exists":true}, "features.dropbox":true}, "_id").should.equal true
@poller._sendToTpds.calledWith([users[0]._id, users[1]._id, users[2]._id,]).should.equal true
@poller._markPollHappened.called.should.equal true
done()
describe "sending user ids to tpds", ->
it 'should put it into json and post it over', (done)->
users = [{_id:"1234"}, {_id:"213oija"}, {_id:"2iojdsjoidsk"}]
@poller._sendToTpds users, =>
@request.post.calledWith({uri:"#{@settings.apis.thirdPartyDataStore.url}/user/poll", json:{user_ids:users}}).should.equal true
done()
describe "marking the last time the poller was made and get it out again", ->
it "should put the date into redis", (done)->
@redis.set = sinon.stub().callsArgWith(2)
@poller._markPollHappened (err)=>
@redis.set.calledWith("LAST_TIME_POLL_HAPPEND_KEY").should.equal true
done()
it "should get the date from redis", (done)->
date = new Date()
@redis.get = sinon.stub().callsArgWith(1, null, date)
@poller.getLastTimePollHappned (err, lastTime)->
lastTime.should.equal date
done()