From d1be7277d54b8d01eba1cfa30bf844b2536c93fc Mon Sep 17 00:00:00 2001 From: Liam McLoughlin Date: Sat, 6 Aug 2011 01:13:08 +0100 Subject: Progress bar is now AJAXified! --- web/ajax.php | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ web/status.php | 36 +++++++++++++++++++++-------- 2 files changed, 98 insertions(+), 10 deletions(-) create mode 100644 web/ajax.php diff --git a/web/ajax.php b/web/ajax.php new file mode 100644 index 0000000..105c893 --- /dev/null +++ b/web/ajax.php @@ -0,0 +1,72 @@ +prepare("SELECT handle FROM builds WHERE id = ?"); + $stmt->bind_param("s", $buildID); + $stmt->execute(); + $stmt->store_result(); + if ($stmt->num_rows == 1) { + $stmt->bind_result($handle); + $stmt->fetch(); + $stmt->close(); + $client = new GearmanClient(); + $client->addServer(); + + $status = $client->jobStatus($handle); + if ($status[0]) { + if ($status[3] != 0) { + // in progress + $ret = array("status" => 1, "num" => $status[2], "den" => $status[3]); + } else { + // not yet processed + $ret = array("status" => 2); + } + } else { + $query = "SELECT returncode, result ". + "FROM builds WHERE id = ?"; + $stmt = $db->prepare($query); + $stmt->bind_param("s", $buildID); + $stmt->execute(); + $stmt->bind_result($returncode, $result); + $stmt->fetch(); + $stmt->close(); + if ($returncode !== null) { + if ($returncode == 0) { + // finished + $ret = array("status" => 0); + } else { + // returned with non-zero status code + $ret = array("status" => 3); + } + } else { + // failed + $ret = array("status" => 4); + } + } + } else { + // job not found + $ret = array("status" => -1); + } + + $db->close(); + + echo json_encode($ret); +?> \ No newline at end of file diff --git a/web/status.php b/web/status.php index ab57a1e..69e8afc 100644 --- a/web/status.php +++ b/web/status.php @@ -49,7 +49,7 @@ if ($status[3] != 0) { $percentage = ceil($status[2]/$status[3]*100); $bres = "Your build is currently running". - " and is ".$percentage."% complete"; + " and is ".$percentage."% complete"; $inprogress = true; } else { $bres = "Task has not yet been processed"; @@ -113,15 +113,31 @@ href="css/ui-lightness/jquery-ui-1.8.14.custom.css"> - - $(document).ready(function() { - $("#progressbar").progressbar({ value: '.$percentage.' }); - }); - '; - } - ?> + + + +
-- cgit v1.2.3-65-gdbad