mirror of
https://github.com/overleaf/overleaf.git
synced 2025-03-13 11:03:54 +00:00
added some null checks and more persistance
This commit is contained in:
parent
59307aa949
commit
2bd88e5319
1 changed files with 27 additions and 8 deletions
|
@ -8,7 +8,7 @@ async = require("async")
|
||||||
exec = require("child_process").exec
|
exec = require("child_process").exec
|
||||||
|
|
||||||
finished_projects_path = "/tmp/finished-projects"
|
finished_projects_path = "/tmp/finished-projects"
|
||||||
|
all_projects_path = "/tmp/all-projects"
|
||||||
|
|
||||||
printProgress = ->
|
printProgress = ->
|
||||||
exec "wc #{finished_projects_path}", (error, results) ->
|
exec "wc #{finished_projects_path}", (error, results) ->
|
||||||
|
@ -18,23 +18,42 @@ printProgress = ->
|
||||||
checkIfFileHasBeenProccessed = (project_id, callback)->
|
checkIfFileHasBeenProccessed = (project_id, callback)->
|
||||||
exec "grep #{project_id} #{finished_projects_path}", (error, results) ->
|
exec "grep #{project_id} #{finished_projects_path}", (error, results) ->
|
||||||
hasBeenProcessed = _.include(results, project_id)
|
hasBeenProcessed = _.include(results, project_id)
|
||||||
console.log hasBeenProcessed, project_id
|
#console.log hasBeenProcessed, project_id
|
||||||
callback(null, hasBeenProcessed)
|
callback(null, hasBeenProcessed)
|
||||||
|
|
||||||
getProjectIds = (callback)->
|
loadProjectIds = (callback)->
|
||||||
|
fs.readFile all_projects_path, "utf-8", (err, data)->
|
||||||
|
console.log data.length
|
||||||
|
ids = data.split("\n")
|
||||||
|
console.log ids.length
|
||||||
|
callback err, ids
|
||||||
|
|
||||||
|
getAndWriteProjectids = (callback)->
|
||||||
console.log "finding all project id's - #{new Date().toString()}"
|
console.log "finding all project id's - #{new Date().toString()}"
|
||||||
db.projects.find {}, {_id:1}, (err, ids)->
|
db.projects.find {}, {_id:1}, (err, ids)->
|
||||||
console.log "total found projects in mongo #{ids.length} - #{new Date().toString()}"
|
console.log "total found projects in mongo #{ids.length} - #{new Date().toString()}"
|
||||||
ids = _.map ids, (id)-> return id._id.toString()
|
ids = _.pluck ids, '_id'
|
||||||
|
ids = _.filter ids, (id)-> id?
|
||||||
|
fileData = ids.join("\n")
|
||||||
|
fs.writeFile all_projects_path, fileData, ->
|
||||||
callback(err, ids)
|
callback(err, ids)
|
||||||
|
|
||||||
|
getProjectIds = (callback)->
|
||||||
|
exists = fs.existsSync all_projects_path
|
||||||
|
if exists
|
||||||
|
loadProjectIds callback
|
||||||
|
else
|
||||||
|
getAndWriteProjectids callback
|
||||||
|
|
||||||
markProjectAsProcessed = (project_id, callback)->
|
markProjectAsProcessed = (project_id, callback)->
|
||||||
fs.appendFile finished_projects_path, "#{project_id}\n", callback
|
fs.appendFile finished_projects_path, "#{project_id}\n", callback
|
||||||
|
|
||||||
getAllDocs = (project_id, callback = (error, docs) ->) ->
|
getAllDocs = (project_id, callback = (error, docs) ->) ->
|
||||||
db.projects.findOne _id:ObjectId(project_id), (error, project) ->
|
db.projects.findOne _id:ObjectId(project_id), (error, project) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
return callback new Errors.NotFoundError("No such project: #{project_id}") if !project?
|
if !project?
|
||||||
|
console.error("No such project: #{project_id}")
|
||||||
|
return callback("no such project #{project_id}")
|
||||||
findAllDocsInProject project, (error, docs) ->
|
findAllDocsInProject project, (error, docs) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
return callback null, docs
|
return callback null, docs
|
||||||
|
@ -78,9 +97,9 @@ saveDocsIntoMongo = (project_id, docs, callback)->
|
||||||
|
|
||||||
|
|
||||||
processNext = (project_id, callback)->
|
processNext = (project_id, callback)->
|
||||||
#console.log("starting to process #{project_id} - #{new Date().toString()}")
|
|
||||||
checkIfFileHasBeenProccessed project_id, (err, hasBeenProcessed)->
|
checkIfFileHasBeenProccessed project_id, (err, hasBeenProcessed)->
|
||||||
if hasBeenProcessed
|
if hasBeenProcessed
|
||||||
|
console.log "#{project_id} already procssed, skipping"
|
||||||
return callback()
|
return callback()
|
||||||
getAllDocs project_id, (err, docs)->
|
getAllDocs project_id, (err, docs)->
|
||||||
if err?
|
if err?
|
||||||
|
|
Loading…
Reference in a new issue