Commit 5f4a09a7 authored by Romain Loth's avatar Romain Loth

[FIX] project view progressbars: add nDocs update and fix loop closure if...

[FIX] project view progressbars: add nDocs update and fix loop closure if several corpora are active
parent 69742909
......@@ -95,7 +95,8 @@
<div class="col-md-5 content">
<a href="/projects/{{project.id}}/corpora/{{corpus.id}}">
<span class="glyphicon glyphicon-file" aria-hidden="true"></span>
{{corpus.name}}, {{ corpus.count }} documents <span id="corpus_{{corpus.id}}_msg">{{ corpus.status_message }}</span>
{{corpus.name}}, <span id="corpus_{{corpus.id}}_ndocs">{{ corpus.count }} documents </span>
<span id="corpus_{{corpus.id}}_msg">{{ corpus.status_message }}</span>
</a>
</div>
<div class="col-md-3 content" id="corpus_{{corpus.id}}_tools">
......@@ -872,10 +873,10 @@
var subStatuses = statuses.slice(1,5)
// console.warn(subStatuses)
for (var j in subStatuses) {
// stepName parmi 'Docs','Ngrams','Index','Lists'
var stepOk = subStatuses[j]['complete']
var stepError = subStatuses[j]['error']
// stepName parmi 'Docs','Ngrams','Index','Lists'
var stepName = subStatuses[j]['action']
// debug
......@@ -895,7 +896,6 @@
+'</a></p>'
)
}
// normal cases: update progressbar ------------
else {
var progressbar = document.getElementById(pgbarId)
......@@ -913,6 +913,12 @@
}
// remove message if any
document.getElementById('corpus_'+crid+'_msg').innerHTML = ""
// for docs parsing, also update nDocs
if (stepName == "Docs" && stepOk) {
var stepProgress = subStatuses[j]['progress']
document.getElementById('corpus_'+crid+'_ndocs')
.innerHTML = (stepProgress-1) + " documents"
}
}
// B: active
else {
......@@ -942,6 +948,7 @@
console.error("Wrong status API return format "
+ "for url" + the_status_url)
}
return null
} // end function
// ---------------------------------------------------
......@@ -949,25 +956,34 @@
// ---------------------------------------------------
function updateCorporaStates(someCorporaIds) {
for (var i in someCorporaIds) {
var crid = someCorporaIds[i]
var the_status_url = "/api/nodes/"+crid+"/status?format=json"
// iterate ajax checks
$.ajax({
type: 'GET',
url: the_status_url,
success: function(data) {
var statuses = data['statuses']
updateCorpusProgressbar(crid, statuses, the_status_url)
},
error: function(data, s) {
console.warning("status GET !! ajax err !! " + s)
console.log(data)
},
beforeSend: function(xhr) {
xhr.setRequestHeader("X-CSRFToken", getCookie("csrftoken"));
}
}) // ajax: did 1 corpus
// !careful with closure, async function & loop on i
// cf stackoverflow.com/a/21819961/2489184
(function(i) {
var myCrid = someCorporaIds[i]
var the_status_url = "/api/nodes/"+myCrid+"/status?format=json"
// iterate ajax checks
$.ajax({
type: 'GET',
url: the_status_url,
success: function(data) {
var statuses = data['statuses']
// console.warn("running callback for corpus id:" + myCrid)
updateCorpusProgressbar(myCrid, statuses, the_status_url)
},
error: function(data, s) {
if (trashedIds[myCrid]) {
return null
}
else {
console.warn("status GET: ajax err (s="+s+")")
console.log(data)
}
},
beforeSend: function(xhr) {
xhr.setRequestHeader("X-CSRFToken", getCookie("csrftoken"));
}
}) // ajax: did 1 corpus
})(i)
} // did all corpora
}
......@@ -991,6 +1007,7 @@
// -----------------------------------------------------
var nChecks = 0
var currentJob = null
function keepCheckingProjectStatus() {
console.log("checking status", nChecks)
nChecks ++
......@@ -1001,7 +1018,7 @@
if (newActiveCorporaIds.length) {
// start remote calls
updateCorporaStates(newActiveCorporaIds)
if (nChecks > 5) {
if (nChecks > {{status_refresh_max_attempts}}) {
// we abandon after 5 checks
console.warn("stopping status checks for corpora:",
newActiveCorporaIds)
......@@ -1010,9 +1027,9 @@
}
else {
// decreasing intervals (preserving DB while "loosing interest")
nextTime = (nChecks+1) * 3000
var nextTime = nChecks * {{status_refresh_initial_interval}}
// schedule next check
setTimeout(keepCheckingProjectStatus, nextTime)
currentJob = setTimeout(keepCheckingProjectStatus, nextTime)
console.log("next status check in", nextTime/1000, "s" )
return false
}
......@@ -1023,6 +1040,10 @@
return true
}
}
function stopCheckingProjectStatus() {
clearTimeout(currentJob)
}
</script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment