Skip to content

Instantly share code, notes, and snippets.

Created October 28, 2009 03:01
Show Gist options
  • Save anonymous/220201 to your computer and use it in GitHub Desktop.
Save anonymous/220201 to your computer and use it in GitHub Desktop.
var GA_IMPORTER = {
check_job: function() {
if (poll === undefined) {
// Create a polling timeout
poll = setInterval(GA_IMPORTER.check_job, 5000); // Every 5 seconds
} else {
if (busy === false) {
busy = true;
// Request for job info
$.getJSON('/admin/play_golf_offers/check_job/',
{
play_golf_offer_spreadsheet_id: id,
t: (new Date()).getTime()
},
function(json){
// Is this the first time?
if (poll !== undefined) {
// If the job isn't running anymore
if (json.state !== "running" && json.state !== "pending") {
// Stop polling
clearInterval(poll);
}
}
// Let the user know
GA_IMPORTER.show_job_status(json);
// Not busy anymore
busy = false;
});
}
}
},
show_job_status: function(json) {
var activity = $("#activity"),
html = "";
switch(json.state) {
case "running":
html += '<h2><img src="/images/spinner.gif" alt="" width="16" height="16" /> Processing data&hellip;</h2>';
break;
case "pending":
html += '<h2><img src="/images/spinner.gif" alt="" width="16" height="16" /> Import will begin shortly&hellip;</h2>';
break;
case "failed":
html += '<h2><img src="/images/exclamation.png" alt="" width="16" height="16" /> Import failed</h2>\
<p>' + json.message + '</p>\
<a href="/admin/play_golf_offers/" title="">Return to offers listing</a>';
break;
case "finished":
html += '<h2><img src="/images/tick.png" alt="" width="16" height="16" /> Finished processing data</h2>\
<p>' + json.message + '</p>\
<a href="/admin/play_golf_offers/" title="">Return to offers listing</a>';
break;
default:
html += '<a href="/admin/play_golf_offers/" title="">Return to offers listing</a>';
}
// Append the update
$(activity).html(html);
// Log for more info's sake
console.log(json);
}
};
var busy = false,
poll;
$(function() {
if (id !== undefined) {
GA_IMPORTER.check_job();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment