I am creating a javascript function to show the status of a running task [ which will run in every 1 hour and it took some time for completion] This function will give an idea to end user that the task is currently running or not
To do this on load event i created a function and set an interval of 10 minutes to that So every 10 minutes it will tell user the status of task
In case if task is found as running on server i would like to reduce the interval to 1 minute . SO as soon as task is finished users will get an idea and they can restart using the web portal. And once its detected as not running would like to revert the interval back to old 10 minute again.
Current implementation is like below
$(function () {
loadSyncStatus();
setInterval(function () {
// Invoke function every 10 minutes (600000)
loadSyncStatus();
}, 600000);
});
function loadSyncStatus() {
var action_url = '@Url.Content("~/Controller/GetSyncStatus")';
$.ajax({
url: action_url,
type: 'GET',
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (response) {
$("#dataSyncStatus").html(response.message);
if(response.running_flag=true){
//check the status every 1 minute *****TODO****
}
else{
//reset the interval back to 10 minutes *****TODO****
}
}
})
}