project state can be stored per project

there is no need to store it per project+user because it reflects the
state of the project itself
This commit is contained in:
Brian Gough 2017-08-02 16:25:47 +01:00
parent cf780fd8bb
commit 4d4cf4f693
2 changed files with 14 additions and 14 deletions

View file

@ -25,7 +25,7 @@ module.exports = ClsiManager =
callback(error, status, result...)
sendRequestOnce: (project_id, user_id, options = {}, callback = (error, status, outputFiles, clsiServerId, validationProblems) ->) ->
ClsiManager._buildRequest project_id, user_id, options, (error, req) ->
ClsiManager._buildRequest project_id, options, (error, req) ->
return callback(error) if error?
logger.log project_id: project_id, "sending compile to CLSI"
console.log "REQUEST", JSON.stringify(req, null, 2)
@ -119,7 +119,7 @@ module.exports = ClsiManager =
VALID_COMPILERS: ["pdflatex", "latex", "xelatex", "lualatex"]
_buildRequest: (project_id, user_id, options={}, callback = (error, request) ->) ->
_buildRequest: (project_id, options={}, callback = (error, request) ->) ->
Project.findById project_id, {}, (error, project) ->
return callback(error) if error?
return callback(new Errors.NotFoundError("project does not exist: #{project_id}")) if !project?
@ -127,7 +127,7 @@ module.exports = ClsiManager =
if project.compiler not in ClsiManager.VALID_COMPILERS
project.compiler = "pdflatex"
ClsiStateManager.checkState project_id, user_id, project, (error, stateOk, state) ->
ClsiStateManager.checkState project_id, project, (error, stateOk, state) ->
return callback(error) if error?
logger.log project_id: project_id, checkState: stateOk, "checked project state"
console.log "OPTIONS ARE", options
@ -151,7 +151,7 @@ module.exports = ClsiManager =
return callback(error) if error?
console.log "DOCS", docs
# FIXME want to store state after project has been sent to clsi
ClsiStateManager.setState project_id, user_id, project, (error, state) ->
ClsiStateManager.setState project_id, project, (error, state) ->
if error?
logger.err err:error, project_id:project_id, "error storing state in redis"
#return callback(error)

View file

@ -4,8 +4,8 @@ rclient = RedisWrapper.client("clsi_state")
logger = require "logger-sharelatex"
crypto = require "crypto"
buildKey = (project_id, user_id)->
return "clsistate:#{project_id}-#{user_id}" # FIXME: should we cluster these on project??
buildKey = (project_id)->
return "clsistate:#{project_id}" # FIXME: should we cluster these on project??
buildState = (project) ->
JSON.stringify project
@ -16,9 +16,9 @@ OneHour = 3600 * 1000
module.exports = ClsiStateManager =
checkState: (project_id, user_id, project, callback = (err, ok) ->) ->
checkState: (project_id, project, callback = (err, ok) ->) ->
newState = buildState(project)
@getState project_id, user_id, (err, oldState) ->
@getState project_id, (err, oldState) ->
return callback(err) if err?
if newState is oldState
hash = crypto.createHash('sha1').update(newState, 'utf8').digest('hex')
@ -26,16 +26,16 @@ module.exports = ClsiStateManager =
else
callback(null,false)
getState: (project_id, user_id, callback = (err, state)->)->
rclient.get buildKey(project_id, user_id), (err, state)->
getState: (project_id, callback = (err, state)->)->
rclient.get buildKey(project_id), (err, state)->
return callback(err) if err?
logger.log project_id: project_id, user_id: user_id, state: state, "got project state from redis"
logger.log project_id: project_id, state: state, "got project state from redis"
return callback(null, state)
setState: (project_id, user_id, project, callback = (err)->)->
setState: (project_id, project, callback = (err)->)->
projectState = buildState project
logger.log project_id: project_id, user_id: user_id, projectState: projectState, "setting project state in redis"
rclient.set buildKey(project_id, user_id), projectState, "PX", OneHour, (err) ->
logger.log project_id: project_id, projectState: projectState, "setting project state in redis"
rclient.set buildKey(project_id), projectState, "PX", OneHour, (err) ->
return callback(err) if err?
hash = crypto.createHash('sha1').update(projectState, 'utf8').digest('hex')
callback(null,hash)