Makes sure the results are send /handled in right order
This commit is contained in:
parent
4df24f457a
commit
567f1f4af0
@ -232,10 +232,11 @@ function nextPage(task, loadError) {
|
|||||||
var failure = loadError || '';
|
var failure = loadError || '';
|
||||||
|
|
||||||
if (!task.pdfDoc) {
|
if (!task.pdfDoc) {
|
||||||
sendTaskResult(canvasToDataURL(), task, failure);
|
sendTaskResult(canvasToDataURL(), task, failure, function () {
|
||||||
log('done' + (failure ? ' (failed !: ' + failure + ')' : '') + '\n');
|
log('done' + (failure ? ' (failed !: ' + failure + ')' : '') + '\n');
|
||||||
++currentTaskIdx;
|
++currentTaskIdx;
|
||||||
nextTask();
|
nextTask();
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,18 +333,12 @@ function nextPage(task, loadError) {
|
|||||||
function snapshotCurrentPage(task, failure) {
|
function snapshotCurrentPage(task, failure) {
|
||||||
log('done, snapshotting... ');
|
log('done, snapshotting... ');
|
||||||
|
|
||||||
sendTaskResult(canvasToDataURL(), task, failure);
|
sendTaskResult(canvasToDataURL(), task, failure, function () {
|
||||||
log('done' + (failure ? ' (failed !: ' + failure + ')' : '') + '\n');
|
log('done' + (failure ? ' (failed !: ' + failure + ')' : '') + '\n');
|
||||||
|
|
||||||
// Set up the next request
|
++task.pageNum;
|
||||||
var backoff = (inFlightRequests > 0) ? inFlightRequests * 10 : 0;
|
nextPage(task);
|
||||||
setTimeout(
|
});
|
||||||
function snapshotCurrentPageSetTimeout() {
|
|
||||||
++task.pageNum;
|
|
||||||
nextPage(task);
|
|
||||||
},
|
|
||||||
backoff
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendQuitRequest() {
|
function sendQuitRequest() {
|
||||||
@ -373,28 +368,25 @@ function done() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendTaskResult(snapshot, task, failure, result) {
|
function sendTaskResult(snapshot, task, failure, callback) {
|
||||||
// Optional result argument is for retrying XHR requests - see below
|
var result = JSON.stringify({
|
||||||
if (!result) {
|
browser: browser,
|
||||||
result = JSON.stringify({
|
id: task.id,
|
||||||
browser: browser,
|
numPages: task.pdfDoc ?
|
||||||
id: task.id,
|
(task.lastPage || task.pdfDoc.numPages) : 0,
|
||||||
numPages: task.pdfDoc ?
|
lastPageNum: getLastPageNum(task),
|
||||||
(task.lastPage || task.pdfDoc.numPages) : 0,
|
failure: failure,
|
||||||
lastPageNum: getLastPageNum(task),
|
file: task.file,
|
||||||
failure: failure,
|
round: task.round,
|
||||||
file: task.file,
|
page: task.pageNum,
|
||||||
round: task.round,
|
snapshot: snapshot,
|
||||||
page: task.pageNum,
|
stats: task.stats.times
|
||||||
snapshot: snapshot,
|
});
|
||||||
stats: task.stats.times
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
send('/submit_task_results', result);
|
send('/submit_task_results', result, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function send(url, message) {
|
function send(url, message, callback) {
|
||||||
var r = new XMLHttpRequest();
|
var r = new XMLHttpRequest();
|
||||||
// (The POST URI is ignored atm.)
|
// (The POST URI is ignored atm.)
|
||||||
r.open('POST', url, true);
|
r.open('POST', url, true);
|
||||||
@ -408,6 +400,9 @@ function send(url, message) {
|
|||||||
send(url, message);
|
send(url, message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
document.getElementById('inFlightCount').innerHTML = inFlightRequests++;
|
document.getElementById('inFlightCount').innerHTML = inFlightRequests++;
|
||||||
|
Loading…
Reference in New Issue
Block a user