[Mageia-sysadm] [333] Add queue current status and suggested time until next submit in the HTTP header
root at mageia.org
root at mageia.org
Fri Jan 21 12:41:03 CET 2011
Revision: 333
Author: pterjan
Date: 2011-01-21 12:41:03 +0100 (Fri, 21 Jan 2011)
Log Message:
-----------
Add queue current status and suggested time until next submit in the HTTP header
Modified Paths:
--------------
build_system/web/index.php
Modified: build_system/web/index.php
===================================================================
--- build_system/web/index.php 2011-01-20 17:35:27 UTC (rev 332)
+++ build_system/web/index.php 2011-01-21 11:41:03 UTC (rev 333)
@@ -24,6 +24,84 @@
error_reporting(E_ALL);
+/**
+ * @param array $pkg
+ *
+ * @return string
+*/
+function pkg_gettype($pkg) {
+ if (array_key_exists("rejected", $pkg["status"]))
+ return "rejected";
+ if (array_key_exists("youri", $pkg["status"])) {
+ if (array_key_exists("src", $pkg["status"]))
+ return "youri";
+ else
+ return "uploaded";
+ }
+ if (array_key_exists("failure", $pkg["status"]))
+ return "failure";
+ if (array_key_exists("done", $pkg["status"]))
+ return "partial";
+ if (array_key_exists("build", $pkg["status"]))
+ return "building";
+ if (array_key_exists("todo", $pkg["status"]))
+ return "todo";
+ return "unknown";
+}
+
+/**
+ * @param integer $num
+ *
+ * @return string
+*/
+function plural($num) {
+ if ($num > 1)
+ return "s";
+}
+
+/**
+ * Return timestamp from package key
+ * @param string $key package submission key
+ *
+ * @return integer
+*/
+
+function key2timestamp($key) {
+ global $tz;
+
+ $date = DateTime::createFromFormat("YmdHis", $key+0, $tz);
+ if ($date <= 0)
+ return null;
+
+ return $date->getTimestamp();
+}
+
+function timediff($start, $end) {
+/**
+ * Return human-readable time difference
+ *
+ * @param integer $start timestamp
+ * @param integer $end timestamp, defaults to now
+ *
+ * @return string
+*/
+ if (is_null($end)) {
+ $end = time();
+ }
+ $diff = $end - $start;
+ if ($diff<60)
+ return $diff . " second" . plural($diff);
+ $diff = round($diff/60);
+ if ($diff<60)
+ return $diff . " minute" . plural($diff);
+ $diff = round($diff/60);
+ if ($diff<24)
+ return $diff . " hour" . plural($diff);
+ $diff = round($diff/24);
+
+ return $diff . " day" . plural($diff);
+}
+
$g_user = isset($_GET['user']) ? htmlentities(strip_tags($_GET['user'])) : null;
$upload_dir = '/home/schedbot/uploads';
@@ -97,84 +175,52 @@
// sort by key in reverse order to have more recent pkgs first
krsort($pkgs);
-/**
- * @param array $pkg
- *
- * @return string
-*/
-function pkg_gettype($pkg) {
- if (array_key_exists("rejected", $pkg["status"]))
- return "rejected";
- if (array_key_exists("youri", $pkg["status"])) {
- if (array_key_exists("src", $pkg["status"]))
- return "youri";
- else
- return "uploaded";
- }
- if (array_key_exists("failure", $pkg["status"]))
- return "failure";
- if (array_key_exists("done", $pkg["status"]))
- return "partial";
- if (array_key_exists("build", $pkg["status"]))
- return "building";
- if (array_key_exists("todo", $pkg["status"]))
- return "todo";
- return "unknown";
-}
+// count all packages statuses
+$stats = array(
+ 'uploaded' => 0,
+ 'failure' => 0,
+ 'todo' => 0,
+ 'building' => 0,
+ 'partial' => 0,
+ 'built' => 0,
+);
+$total = count($pkgs);
-/**
- * @param integer $num
- *
- * @return string
-*/
-function plural($num) {
- if ($num > 1)
- return "s";
-}
+// count users' packages
+$users = array();
-/**
- * Return timestamp from package key
- * @param string $key package submission key
- *
- * @return integer
-*/
+if ($total > 0) {
+ foreach ($pkgs as $key => $p) {
+ $pkgs[$key]['type'] = pkg_gettype($p);
-function key2timestamp($key) {
- global $tz;
+ $stats[$pkgs[$key]['type']] += 1;
- $date = DateTime::createFromFormat("YmdHis", $key+0, $tz);
- if ($date <= 0)
- return null;
-
- return $date->getTimestamp();
+ if (!array_key_exists($p['user'], $users))
+ $users[$p['user']] = 1;
+ else
+ $users[$p['user']] += 1;
+ }
}
-function timediff($start, $end) {
-/**
- * Return human-readable time difference
- *
- * @param integer $start timestamp
- * @param integer $end timestamp, defaults to now
- *
- * @return string
-*/
- if (is_null($end)) {
- $end = time();
- }
- $diff = $end - $start;
- if ($diff<60)
- return $diff . " second" . plural($diff);
- $diff = round($diff/60);
- if ($diff<60)
- return $diff . " minute" . plural($diff);
- $diff = round($diff/60);
- if ($diff<24)
- return $diff . " hour" . plural($diff);
- $diff = round($diff/24);
+// feedback labels
+$badges = array(
+ 'uploaded' => 'Congrats %s! \o/',
+ 'failure' => 'Booooo! /o\\',
+ 'todo' => '',
+ 'building' => '',
+ 'partial' => '',
+ 'built' => ''
+);
- return $diff . " day" . plural($diff);
+foreach ($stats as $k => $v) {
+ Header("X-BS-Queue-$k: $v");
}
+$w = $stats['todo'] - 10;
+if($w < 0)
+ $w = 0;
+$w = $w * 60;
+Header("X-BS-Throttle: $w");
?>
<!DOCTYPE html>
<html lang="en">
@@ -251,41 +297,8 @@
<td class="status-box"></td>
T;
-// count all packages statuses
-$stats = array(
- 'uploaded' => 0,
- 'failure' => 0,
- 'todo' => 0,
- 'building' => 0,
- 'partial' => 0,
- 'built' => 0,
-);
-$total = count($pkgs);
-
-// count users' packages
-$users = array();
-
-// feedback labels
-$badges = array(
- 'uploaded' => 'Congrats %s! \o/',
- 'failure' => 'Booooo! /o\\',
- 'todo' => '',
- 'building' => '',
- 'partial' => '',
- 'built' => ''
-);
-
if ($total > 0) {
foreach ($pkgs as $key => $p) {
- $p['type'] = pkg_gettype($p);
-
- $stats[$p['type']] += 1;
-
- if (!array_key_exists($p['user'], $users))
- $users[$p['user']] = 1;
- else
- $users[$p['user']] += 1;
-
$s .= sprintf($tmpl,
$p['type'],
timediff(key2timestamp($key)) . ' ago',
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/mageia-sysadm/attachments/20110121/d701158a/attachment-0001.html>
More information about the Mageia-sysadm
mailing list