mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 02:15:13 -05:00
revert random TTL in favour of delay in archiving
there could be some issues with newer packs expiring before older ones
This commit is contained in:
parent
29da5797e3
commit
ac5d59211d
2 changed files with 29 additions and 29 deletions
|
@ -526,13 +526,13 @@ module.exports = PackManager =
|
||||||
setTTLOnArchivedPack: (project_id, doc_id, pack_id, callback) ->
|
setTTLOnArchivedPack: (project_id, doc_id, pack_id, callback) ->
|
||||||
db.docHistory.findAndModify {
|
db.docHistory.findAndModify {
|
||||||
query: {_id: pack_id}
|
query: {_id: pack_id}
|
||||||
update: {$set: {expiresAt: PackManager._getOneDayInFutureWithRandomDelay()}}
|
update: {$set: {expiresAt: new Date(Date.now() + 1*DAYS)}}
|
||||||
}, (err) ->
|
}, (err) ->
|
||||||
logger.log {project_id, doc_id, pack_id}, "set expiry on pack"
|
logger.log {project_id, doc_id, pack_id}, "set expiry on pack"
|
||||||
callback()
|
callback()
|
||||||
|
|
||||||
|
|
||||||
_getOneDayInFutureWithRandomDelay: ->
|
# _getOneDayInFutureWithRandomDelay: ->
|
||||||
thirtyMins = 1000 * 60 * 30
|
# thirtyMins = 1000 * 60 * 30
|
||||||
randomThirtyMinMax = Math.ceil(Math.random() * thirtyMins)
|
# randomThirtyMinMax = Math.ceil(Math.random() * thirtyMins)
|
||||||
return new Date(Date.now() + randomThirtyMinMax + 1*DAYS)
|
# return new Date(Date.now() + randomThirtyMinMax + 1*DAYS)
|
||||||
|
|
|
@ -334,32 +334,32 @@ describe "PackManager", ->
|
||||||
it "should return with no error", ->
|
it "should return with no error", ->
|
||||||
@callback.calledWith(undefined).should.equal true
|
@callback.calledWith(undefined).should.equal true
|
||||||
|
|
||||||
describe "setTTLOnArchivedPack", ->
|
# describe "setTTLOnArchivedPack", ->
|
||||||
beforeEach ->
|
# beforeEach ->
|
||||||
@pack_id = "somepackid"
|
# @pack_id = "somepackid"
|
||||||
@onedayinms = 86400000
|
# @onedayinms = 86400000
|
||||||
@db.docHistory =
|
# @db.docHistory =
|
||||||
findAndModify : sinon.stub().callsArgWith(1)
|
# findAndModify : sinon.stub().callsArgWith(1)
|
||||||
|
|
||||||
it "should set expires to 1 day", (done)->
|
# it "should set expires to 1 day", (done)->
|
||||||
@PackManager._getOneDayInFutureWithRandomDelay = sinon.stub().returns(@onedayinms)
|
# #@PackManager._getOneDayInFutureWithRandomDelay = sinon.stub().returns(@onedayinms)
|
||||||
@PackManager.setTTLOnArchivedPack @project_id, @doc_id, @pack_id, =>
|
# @PackManager.setTTLOnArchivedPack @project_id, @doc_id, @pack_id, =>
|
||||||
args = @db.docHistory.findAndModify.args[0][0]
|
# args = @db.docHistory.findAndModify.args[0][0]
|
||||||
args.query._id.should.equal @pack_id
|
# args.query._id.should.equal @pack_id
|
||||||
args.update['$set'].expiresAt.should.equal @onedayinms
|
# args.update['$set'].expiresAt.should.equal @onedayinms
|
||||||
done()
|
# done()
|
||||||
|
|
||||||
|
|
||||||
describe "_getOneDayInFutureWithRandomDelay", ->
|
# describe "_getOneDayInFutureWithRandomDelay", ->
|
||||||
beforeEach ->
|
# beforeEach ->
|
||||||
@onedayinms = 86400000
|
# @onedayinms = 86400000
|
||||||
@thirtyMins = 1000 * 60 * 30
|
# @thirtyMins = 1000 * 60 * 30
|
||||||
|
|
||||||
it "should give 1 day + 30 mins random time", (done)->
|
# it "should give 1 day + 30 mins random time", (done)->
|
||||||
loops = 10000
|
# loops = 10000
|
||||||
while --loops > 0
|
# while --loops > 0
|
||||||
randomDelay = @PackManager._getOneDayInFutureWithRandomDelay() - new Date(Date.now() + @onedayinms)
|
# randomDelay = @PackManager._getOneDayInFutureWithRandomDelay() - new Date(Date.now() + @onedayinms)
|
||||||
randomDelay.should.be.above(0)
|
# randomDelay.should.be.above(0)
|
||||||
randomDelay.should.be.below(@thirtyMins + 1)
|
# randomDelay.should.be.below(@thirtyMins + 1)
|
||||||
done()
|
# done()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue