Fix #26 API redirects to the response before it's written to disk

This commit is contained in:
Gaël Métais
2014-12-19 14:34:47 +01:00
parent 482a890447
commit 0776551aa7
+15 -6
View File
@@ -52,16 +52,25 @@ var ApiController = function(app) {
.then(function(data) {
debug('Success');
runsDatastore.markAsComplete(run.runId);
// Save result in datastore
data.runId = run.runId;
resultsDatastore.saveResult(data);
resultsDatastore.saveResult(data)
.then(function() {
// Send result if the user was waiting
if (run.params.waitForResponse) {
res.redirect(302, '/api/results/' + run.runId);
}
runsDatastore.markAsComplete(run.runId);
// Send result if the user was waiting
if (run.params.waitForResponse) {
res.redirect(302, '/api/results/' + run.runId);
}
})
.fail(function(err) {
debug('Saving results to resultsDatastore failed:');
debug(err);
});
}).fail(function(err) {