var intervalTime = 2000; var timeoutTime = 600000; var interval = null; $(function () { var queuestatus = $("#qujo_status").first(); var jobstatus = $("#jobs_status").first(); var resqstatus = $("#resque_status").first(); function qRun(){ queuestatus.addClass('label-inverse'); } function qStop(){ queuestatus.removeClass('label-inverse'); } function qFine(){ queuestatus.removeClass("label-important"); } function qError(){ queuestatus.addClass("label-important"); } function qWarn(){ queuestatus.addClass("label-warning"); } function jFine(){ jobstatus.removeClass("badge-important"); } function jError(){ jobstatus.addClass("badge-important"); } function jText(v){ jobstatus.text(v); } function rFine(){ resqstatus.removeClass("badge-important"); } function rError(){ resqstatus.addClass("badge-important"); } function rText(v){ resqstatus.text(v); } function updateStatus() { console.log("update status"); qRun(); console.log("status: get"); $.get("/jobs/status",function (d) { console.log("status: return"); qStop(); qFine(); jFine(); jText(d["jobs"]["count"]); if (d["jobs"]["error"]) { qError(); jError(); } rFine(); rText(d["resque"]["count"]); if (d["resque"]["error"]) { qError(); rError(); } }).fail(function (d) { console.log("status: fail: "); console.log(d); qStop(); qError(); jError(); rError(); jText('!'); rText('!'); console.log("disable interval"); clearInterval(interval); }); } if (jobstatus.size()) { interval = setInterval(updateStatus, intervalTime); timeout = setTimeout(function(){ console.log("disable interval"); qWarn(); clearInterval(interval); }, timeoutTime); // disable interval after 10 minutes of inactivity } $(".create_job").on("click", function () { var c = $(this).attr("klass"); console.log("create job"); $.post("/jobs", {job: {_type: c}}, function (d) { console.log("create job returned") }); }); $(document).delegate(".job_cancel", "click", function (e) { e.preventDefault(); var id = $(this).attr("data-id"); var tr = $(this).parent("td").parent("tr"); var u = "/jobs/" + id + ".json"; console.log("job_cancel:" + u); $.post(u, { _method: "DELETE" }, function () { console.log("returned"); if (tr) { // $(tr).fadeOut(500, function(){ $(this).remove();}) $(tr).addClass("deleting"); } }); }); $(document).delegate(".job_retry", "click", function (e) { e.preventDefault(); var id = $(this).attr("data-id"); if ($(this).hasClass("disabled")) { console.log("job " + id + "clicked, but disabled"); } else { console.log("job " + id + " sending retry"); $(this).addClass("disabled"); $.post("/jobs/" + id + "/refresh.json", {}, function () { console.log("refresh sent"); }); } }); $(document).delegate(".job_accept", "click", function (e) { e.preventDefault(); var id = $(this).attr("data-id"); var tp = $(this).attr("data-type"); var tr = $(this).parent("td").parent("tr"); if (id != "nil" && tp != "unknown") { var u = "/jobs/" + id + "/accept.json"; console.log("accept_me:" + u); $.post(u, {}, function () { console.log("returned"); if (tr) { // $(tr).fadeOut(500, function(){ $(this).remove();}) $(tr).addClass("deleting"); } }); } }); $(document).delegate(".job_accept_all", "click", function (e) { e.preventDefault(); var id = $(this).attr("data-id"); var tp = $(this).attr("data-type"); var tr = $(this).parent("td").parent("tr"); if (id != "nil" && tp != "unknown") { var u = "/jobs/all/accept.json"; console.log("accept_me:" + u); $.post(u, {}, function () { console.log("returned"); if (tr) { // $(tr).fadeOut(500, function(){ $(this).remove();}) $(tr).addClass("deleting"); } }); } }); });