Skip to content

Commit

Permalink
[Hardening] More readable name for celery files results store / seria…
Browse files Browse the repository at this point in the history
…lized JS async calls on LayerInfo upload prototype
  • Loading branch information
afabiani committed Sep 6, 2019
1 parent 8ae17dc commit 6cd3ec5
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 59 deletions.
2 changes: 1 addition & 1 deletion geonode/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,7 @@ def get_geonode_catalogue_service():
else:
_BROKER_URL = LOCAL_SIGNALS_BROKER_URL
CELERY_RESULT_BACKEND_PATH = os.getenv(
'CELERY_RESULT_BACKEND_PATH', os.path.join(PROJECT_ROOT, 'results'))
'CELERY_RESULT_BACKEND_PATH', os.path.join(PROJECT_ROOT, '.celery_results'))
if not os.path.exists(CELERY_RESULT_BACKEND_PATH):
os.makedirs(CELERY_RESULT_BACKEND_PATH)
CELERY_RESULT_BACKEND = 'file:///%s' % CELERY_RESULT_BACKEND_PATH
Expand Down
136 changes: 80 additions & 56 deletions geonode/static/geonode/js/upload/LayerInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ define(function (require, exports) {
* @params {options}
* @returns {string}
*/
LayerInfo.prototype.doFinal = function (resp) {
LayerInfo.prototype.doFinal = function (resp, callback, array) {
var self = this;
if (resp.hasOwnProperty('redirect_to') && resp.redirect_to.indexOf('upload/final') > -1) {
common.make_request({
Expand All @@ -429,6 +429,8 @@ define(function (require, exports) {
failure: function (resp, status) {
self.polling = false;
self.markError(resp.errors, status);

callback(array);
},
success: function (resp, status) {
self.polling = false;
Expand All @@ -440,13 +442,17 @@ define(function (require, exports) {
});
} else if (resp.status === "pending") {
setTimeout(function() {
self.doFinal(resp);
self.doFinal(resp, callback, array);
}, 5000);
} else if (resp.status === 'error') {
self.polling = false;
self.markError(resp.error_msg, resp.status);

callback(array);
} else {
self.displayUploadedLayerLinks(resp);

callback(array);
}
}
});
Expand All @@ -468,19 +474,28 @@ define(function (require, exports) {
empty: 'true'
});
$("#" + element).on('click', resp, self.doResume);

callback(array);

return;
} else if (resp.status === "other") {
self.logStatus({
msg:'<p>' + gettext('You need to specify more information in order to complete your upload') + '</p>',
level: 'alert-success',
empty: 'true'
});

callback(array);
} else if (resp.status === 'error') {
self.polling = false;
self.markError(resp.error_msg, resp.status);

callback(array);
} else if (resp.success === true) {
self.polling = false;
self.displayUploadedLayerLinks(resp);

callback(array);
} else {
self.polling = false;
resp.errors = 'Unexpected Error';
Expand All @@ -489,6 +504,8 @@ define(function (require, exports) {
level: 'alert-error',
empty: 'true'
});

callback(array);
}

};
Expand All @@ -498,7 +515,7 @@ define(function (require, exports) {
* @params {options}
* @returns {string}
*/
LayerInfo.prototype.doStep = function (resp) {
LayerInfo.prototype.doStep = function (resp, callback, array) {
var self = this;
self.logStatus({
msg: '<p>' + gettext('Performing GeoServer Config Step') + '</p>',
Expand All @@ -516,20 +533,24 @@ define(function (require, exports) {
} else {
self.markError(resp.errors, status);
}

callback(array);
},
success: function (resp, status) {
self.id = resp.id;
if (resp.status === 'incomplete') {
if (resp.input_required === true) {
self.doFinal(resp);
self.doFinal(resp, callback, array);
} else {
self.doStep(resp);
self.doStep(resp, callback, array);
}
} else if (resp.status === 'error') {
self.polling = false;
self.markError(resp.error_msg, resp.status);

callback(array);
} else if (resp.redirect_to.indexOf('upload/final') > -1) {
self.doFinal(resp);
self.doFinal(resp, callback, array);
} else {
window.location = resp.url;
}
Expand All @@ -538,10 +559,12 @@ define(function (require, exports) {
} else if (resp.success === true && resp.status === 'error') {
self.polling = false;
self.markError(resp.error_msg, resp.status);

callback(array);
} else if (resp.success === true && typeof resp.url != 'undefined') {
self.doFinal(resp);
self.doFinal(resp, callback, array);
} else if (resp.success === true && resp.redirect_to.indexOf('upload/final') > -1) {
self.doFinal(resp);
self.doFinal(resp, callback, array);
}
};

Expand All @@ -550,57 +573,58 @@ define(function (require, exports) {
* @params
* @returns
*/
LayerInfo.prototype.uploadFiles = function () {
var form_data = this.prepareFormData(),
self = this;
var prog = "";
LayerInfo.prototype.uploadFiles = function (callback, array) {
var form_data = this.prepareFormData(), self = this;
var prog = "";

$.ajax({
url: form_target,
async: true,
url: form_target,
async: true,
mode: "queue",
type: "POST",
data: form_data,
timeout: 15000,
processData: false,
contentType: false,
xhr: function() {
var req = $.ajaxSettings.xhr();
if (req) {
req.upload.addEventListener('progress', function(evt) {
console.log(req.status)
if(evt.lengthComputable) {
var pct = (evt.loaded / evt.total) * 100;
$('#prog > .progress-bar').css('width', pct.toPrecision(3) + '%');
}
}, false);
}
return req;
},
beforeSend: function () {
self.markStart();
self.polling = true;
self.startPolling();
},
error: function (jqXHR) {
self.polling = false;
if(jqXHR.status === 500 || jqXHR.status === 0 || jqXHR.readyState === 0){
self.markError('Server Error: ' + jqXHR.statusText + gettext('<br>Please check your network connection. In case of Layer Upload make sure GeoServer is running and accepting connections.'));
} else if (jqXHR.status === 400 || jqXHR.status === 404) {
self.markError('Client Error: ' + jqXHR.statusText + gettext('<br>Bad request or URL not found.'));
} else {
self.markError(gettext('Unexpected Error'));
}
},
success: function (resp, status) {
self.logStatus({
msg: '<p>' + gettext('Layer files uploaded, configuring in GeoServer') + '</p>',
level: 'alert-success',
empty: 'true'
});
self.id = resp.id;
self.doStep(resp);
}
type: "POST",
data: form_data,
timeout: 600000, // sets timeout to 10 minutes
processData: false,
contentType: false,
xhr: function() {
var req = $.ajaxSettings.xhr();
if (req) {
req.upload.addEventListener('progress', function(evt) {
console.log(req.status)
if(evt.lengthComputable) {
var pct = (evt.loaded / evt.total) * 100;
$('#prog > .progress-bar').css('width', pct.toPrecision(3) + '%');
}
}, false);
}
return req;
},
beforeSend: function () {
self.markStart();
self.polling = true;
self.startPolling();
},
error: function (jqXHR) {
self.polling = false;
if(jqXHR.status === 500 || jqXHR.status === 0 || jqXHR.readyState === 0){
self.markError('Server Error: ' + jqXHR.statusText + gettext('<br>Please check your network connection. In case of Layer Upload make sure GeoServer is running and accepting connections.'));
} else if (jqXHR.status === 400 || jqXHR.status === 404) {
self.markError('Client Error: ' + jqXHR.statusText + gettext('<br>Bad request or URL not found.'));
} else {
self.markError(gettext('Unexpected Error'));
}

callback(array);
},
success: function (resp, status) {
self.logStatus({
msg: '<p>' + gettext('Layer files uploaded, configuring in GeoServer') + '</p>',
level: 'alert-success',
empty: 'true'
});
self.id = resp.id;
self.doStep(resp, callback, array);
}
});
};

Expand Down
17 changes: 15 additions & 2 deletions geonode/static/geonode/js/upload/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ define(['underscore',
types,
buildFileInfo,
displayFiles,
doUpload,
doUploads,
doSrs,
doDelete,
Expand Down Expand Up @@ -272,6 +273,13 @@ define(['underscore',
return false;
};

/** Function to Upload the selected files to the server
*/
doUpload = function (layers) {
if (layers.length > 0) {
layers[0].uploadFiles(doUpload, layers.slice(1, layers.length));
}
};

/** Function to Upload the selected files to the server
*
Expand All @@ -287,14 +295,19 @@ define(['underscore',
if ($.isEmptyObject(layers) || !checked) {
alert(gettext('You are trying to upload an incomplete set of files or not all mandatory options have been validated.\n\nPlease check for errors in the form!'));
} else {
$.each(layers, function (name, layerinfo) {
/* $.each(layers, function (name, layerinfo) {
layerinfo.uploadFiles();
}); */

var layerInfos = [];
$.each(layers, function (name, layerinfo) {
layerInfos.push(layerinfo);
});
doUpload(layerInfos);
}
return false;
};


/** Initialization function. Called from main.js
*
* @params
Expand Down

0 comments on commit 6cd3ec5

Please sign in to comment.