mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
clean up state manager
This commit is contained in:
parent
a955b8fcc9
commit
0a859d3b33
2 changed files with 23 additions and 20 deletions
|
@ -128,10 +128,9 @@ module.exports = ClsiManager =
|
||||||
if project.compiler not in ClsiManager.VALID_COMPILERS
|
if project.compiler not in ClsiManager.VALID_COMPILERS
|
||||||
project.compiler = "pdflatex"
|
project.compiler = "pdflatex"
|
||||||
|
|
||||||
ClsiStateManager.checkState project_id, project, (error, stateOk, state) ->
|
ClsiStateManager.checkProjectStateMatch project_id, project, (error, stateOk, projectState) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
logger.log project_id: project_id, checkState: stateOk, "checked project state"
|
logger.log project_id: project_id, checkState: stateOk, "checked project state"
|
||||||
console.log "OPTIONS ARE", options
|
|
||||||
if stateOk and not options.state? # incremental
|
if stateOk and not options.state? # incremental
|
||||||
ClsiManager._getContentFromDocUpdater project_id, (error, docUpdaterDocs) ->
|
ClsiManager._getContentFromDocUpdater project_id, (error, docUpdaterDocs) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
|
@ -145,18 +144,18 @@ module.exports = ClsiManager =
|
||||||
path = docPath[doc._id]
|
path = docPath[doc._id]
|
||||||
docs[path] = doc
|
docs[path] = doc
|
||||||
console.log "MAPPED DOCS", docs
|
console.log "MAPPED DOCS", docs
|
||||||
options.incremental = state
|
options.incremental = projectState
|
||||||
ClsiManager._finaliseRequest project_id, options, project, docs, [], callback
|
ClsiManager._finaliseRequest project_id, options, project, docs, [], callback
|
||||||
else
|
else
|
||||||
ClsiManager._getContentFromMongo project_id, (error, docs, files) ->
|
ClsiManager._getContentFromMongo project_id, (error, docs, files) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
console.log "DOCS", docs
|
console.log "DOCS", docs
|
||||||
# FIXME want to store state after project has been sent to clsi
|
# FIXME want to store state after project has been sent to clsi
|
||||||
ClsiStateManager.setState project_id, project, (error, state) ->
|
ClsiStateManager.setProjectState project_id, project, (error, projectState) ->
|
||||||
if error?
|
if error?
|
||||||
logger.err err:error, project_id:project_id, "error storing state in redis"
|
logger.err err:error, project_id:project_id, "error storing state in redis"
|
||||||
#return callback(error)
|
#return callback(error)
|
||||||
options.state = state
|
options.state = projectState
|
||||||
ClsiManager._finaliseRequest project_id, options, project, docs, files, callback
|
ClsiManager._finaliseRequest project_id, options, project, docs, files, callback
|
||||||
|
|
||||||
_getContentFromDocUpdater: (project_id, callback = (error, docs) ->) ->
|
_getContentFromDocUpdater: (project_id, callback = (error, docs) ->) ->
|
||||||
|
|
|
@ -7,8 +7,19 @@ crypto = require "crypto"
|
||||||
buildKey = (project_id)->
|
buildKey = (project_id)->
|
||||||
return "clsistate:#{project_id}" # FIXME: should we cluster these on project??
|
return "clsistate:#{project_id}" # FIXME: should we cluster these on project??
|
||||||
|
|
||||||
|
# the "state" of a project is a hash of the relevant attributes in the
|
||||||
|
# project object in this case we only need the rootFolder.
|
||||||
|
#
|
||||||
|
# When it changes the full set of files on the CLSI will need to be
|
||||||
|
# updated. If it doesn't change then we can overwrite changed docs in
|
||||||
|
# place on the clsi, getting them from the docupdater.
|
||||||
|
#
|
||||||
|
# The docupdater is also responsible for unsetting the key in redis if
|
||||||
|
# it removes any documents from the doc updater.
|
||||||
|
|
||||||
buildState = (project) ->
|
buildState = (project) ->
|
||||||
JSON.stringify project
|
json = JSON.stringify(project.rootFolder)
|
||||||
|
return crypto.createHash('sha1').update(json, 'utf8').digest('hex')
|
||||||
|
|
||||||
clsiStateEnabled = Settings.clsiState
|
clsiStateEnabled = Settings.clsiState
|
||||||
|
|
||||||
|
@ -16,26 +27,19 @@ OneHour = 3600 * 1000
|
||||||
|
|
||||||
module.exports = ClsiStateManager =
|
module.exports = ClsiStateManager =
|
||||||
|
|
||||||
checkState: (project_id, project, callback = (err, ok) ->) ->
|
checkProjectStateMatch: (project_id, project, callback = (err, ok) ->) ->
|
||||||
newState = buildState(project)
|
newState = buildState(project)
|
||||||
@getState project_id, (err, oldState) ->
|
rclient.get buildKey(project_id), (err, oldState) ->
|
||||||
return callback(err) if err?
|
return callback(err) if err?
|
||||||
|
logger.log project_id: project_id, new_state: newState, old_state: oldState, "got project state from redis"
|
||||||
if newState is oldState
|
if newState is oldState
|
||||||
hash = crypto.createHash('sha1').update(newState, 'utf8').digest('hex')
|
callback(null,true,oldState)
|
||||||
callback(null,true,hash)
|
|
||||||
else
|
else
|
||||||
callback(null,false)
|
callback(null,false)
|
||||||
|
|
||||||
getState: (project_id, callback = (err, state)->)->
|
setProjectState: (project_id, project, callback = (err)->)->
|
||||||
rclient.get buildKey(project_id), (err, state)->
|
projectState = buildState(project)
|
||||||
return callback(err) if err?
|
|
||||||
logger.log project_id: project_id, state: state, "got project state from redis"
|
|
||||||
return callback(null, state)
|
|
||||||
|
|
||||||
setState: (project_id, project, callback = (err)->)->
|
|
||||||
projectState = buildState project
|
|
||||||
logger.log project_id: project_id, projectState: projectState, "setting project state in redis"
|
logger.log project_id: project_id, projectState: projectState, "setting project state in redis"
|
||||||
rclient.set buildKey(project_id), projectState, "PX", OneHour, (err) ->
|
rclient.set buildKey(project_id), projectState, "PX", OneHour, (err) ->
|
||||||
return callback(err) if err?
|
return callback(err) if err?
|
||||||
hash = crypto.createHash('sha1').update(projectState, 'utf8').digest('hex')
|
callback(null,projectState)
|
||||||
callback(null,hash)
|
|
||||||
|
|
Loading…
Reference in a new issue