Allow migrate script to process multi docs at once

This commit is contained in:
James Allen 2016-07-07 16:29:01 +01:00
parent 6bc78ccf77
commit 9bd7c0017d
2 changed files with 26 additions and 19 deletions

View file

@ -32,18 +32,18 @@ module.exports =
docVersion: ({doc_id}) -> "DocVersion:#{doc_id}"
projectKey: ({doc_id}) -> "ProjectId:#{doc_id}"
docsInProject: ({project_id}) -> "DocsIn:#{project_id}"
# }, {
# cluster: [{
# port: "7000"
# host: "localhost"
# }]
# key_schema:
# blockingKey: ({doc_id}) -> "Blocking:{#{doc_id}}"
# docLines: ({doc_id}) -> "doclines:{#{doc_id}}"
# docOps: ({doc_id}) -> "DocOps:{#{doc_id}}"
# docVersion: ({doc_id}) -> "DocVersion:{#{doc_id}}"
# projectKey: ({doc_id}) -> "ProjectId:{#{doc_id}}"
# docsInProject: ({project_id}) -> "DocsIn:{#{project_id}}"
}, {
cluster: [{
port: "7000"
host: "localhost"
}]
key_schema:
blockingKey: ({doc_id}) -> "Blocking:{#{doc_id}}"
docLines: ({doc_id}) -> "doclines:{#{doc_id}}"
docOps: ({doc_id}) -> "DocOps:{#{doc_id}}"
docVersion: ({doc_id}) -> "DocVersion:{#{doc_id}}"
projectKey: ({doc_id}) -> "ProjectId:{#{doc_id}}"
docsInProject: ({project_id}) -> "DocsIn:{#{project_id}}"
}]
max_doc_length: 2 * 1024 * 1024 # 2mb

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)