|
|
@@ -7,8 +7,19 @@ crypto = require "crypto"
|
|
|
buildKey = (project_id)->
|
|
|
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) ->
|
|
|
- JSON.stringify project
|
|
|
+ json = JSON.stringify(project.rootFolder)
|
|
|
+ return crypto.createHash('sha1').update(json, 'utf8').digest('hex')
|
|
|
|
|
|
clsiStateEnabled = Settings.clsiState
|
|
|
|
|
|
@@ -16,26 +27,19 @@ OneHour = 3600 * 1000
|
|
|
|
|
|
module.exports = ClsiStateManager =
|
|
|
|
|
|
- checkState: (project_id, project, callback = (err, ok) ->) ->
|
|
|
+ checkProjectStateMatch: (project_id, project, callback = (err, ok) ->) ->
|
|
|
newState = buildState(project)
|
|
|
- @getState project_id, (err, oldState) ->
|
|
|
+ rclient.get buildKey(project_id), (err, oldState) ->
|
|
|
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
|
|
|
- hash = crypto.createHash('sha1').update(newState, 'utf8').digest('hex')
|
|
|
- callback(null,true,hash)
|
|
|
+ callback(null,true,oldState)
|
|
|
else
|
|
|
callback(null,false)
|
|
|
|
|
|
- getState: (project_id, callback = (err, state)->)->
|
|
|
- rclient.get buildKey(project_id), (err, state)->
|
|
|
- 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
|
|
|
+ setProjectState: (project_id, project, callback = (err)->)->
|
|
|
+ projectState = buildState(project)
|
|
|
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)
|
|
|
+ callback(null,projectState)
|