Merge branch 'master' into sk-dockerize-tests

This commit is contained in:
Shane Kilkelly 2016-07-08 13:37:04 +01:00
commit 28fda02d2d
2 changed files with 24 additions and 11 deletions

View file

@ -130,12 +130,15 @@ module.exports = RedisManager =
return callback(error) if error?
[lines, version, ops, project_id] = results
multi = rclient.multi()
multi.set keys.docLines(doc_id:doc_id), lines
multi.set keys.docVersion(doc_id:doc_id), version
if lines?
multi.set keys.docLines(doc_id:doc_id), lines
if version?
multi.set keys.docVersion(doc_id:doc_id), version
multi.del keys.docOps(doc_id:doc_id)
if ops.length > 0
multi.rpush keys.docOps(doc_id:doc_id), ops...
multi.set keys.projectKey(doc_id:doc_id), project_id
if project_id?
multi.set keys.projectKey(doc_id:doc_id), project_id
multi.exec (error) ->
return callback(error) if error?
return callback null, project_id
@ -143,4 +146,7 @@ module.exports = RedisManager =
getAndSetProject: (project_id, callback = (error) ->) ->
rclient.smembers keys.docsInProject(project_id: project_id), (error, doc_ids) ->
return callback(error) if error?
rclient.sadd keys.docsInProject(project_id: project_id), doc_ids..., callback
if doc_ids.length > 0
rclient.sadd keys.docsInProject(project_id: project_id), doc_ids..., callback
else
callback()

View file

@ -2,6 +2,8 @@ RedisManager = require "./app/coffee/RedisManager"
UpdateManager = require "./app/coffee/UpdateManager"
LockManager = require "./app/coffee/LockManager"
async = require "async"
handleErrorInsideLock = (doc_id, lockValue, original_error, callback = (error) ->) ->
LockManager.releaseLock doc_id, lockValue, (lock_error) ->
callback(original_error)
@ -17,13 +19,18 @@ migrateDoc = (doc_id, callback = (error) ->) ->
return callback(error) if error?
UpdateManager.continueProcessingUpdatesWithLock project_id, doc_id, callback
doc_id = process.argv[2]
if !doc_id?
console.log "Usage: coffee migrate.coffee DOC_ID"
doc_ids = process.argv.slice(2)
if doc_ids.length == 0
console.log "Usage: coffee migrate.coffee DOC_ID [DOC_ID ...]"
process.exit(1)
migrateDoc doc_id, (error) ->
jobs = []
for doc_id in doc_ids
do (doc_id) ->
jobs.push (cb) ->
console.log "MIGRATING #{doc_id}"
migrateDoc doc_id, cb
async.series jobs, (error) ->
throw error if error?
setTimeout () ->
process.exit(0)
, 200
process.exit(0)