summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib.php36
-rw-r--r--test_index.php26
2 files changed, 38 insertions, 24 deletions
diff --git a/lib.php b/lib.php
index 5feb424..e00ed27 100644
--- a/lib.php
+++ b/lib.php
@@ -134,3 +134,39 @@ function timesort($a, $b)
return 0;
}
}
+
+
+/**
+ * Publish BS stats as HTTP headers for remote services to adapt.
+ *
+ * @param array $stats
+ * @param array $last_package
+ *
+ * @return void
+*/
+function publish_stats_headers($stats, $last_package = null)
+{
+ 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");
+
+ if (!is_null($last_package)) {
+ header("X-BS-Package-Status: ".$last_package['type']);
+ }
+
+ $buildtime_total = $buildtime_total / 60;
+ header(sprintf('X-BS-Buildtime: %d', round($buildtime_total)));
+
+
+ $buildtime_avg = ($build_count == 0) ?
+ 0 :
+ round($buildtime_total / $build_count, 2);
+ header(sprintf('X-BS-Buildtime-Average: %5.2f', $buildtime_avg));
+}
diff --git a/test_index.php b/test_index.php
index 61ddb79..fa83a4e 100644
--- a/test_index.php
+++ b/test_index.php
@@ -180,31 +180,9 @@ if (file_exists('/var/lib/schedbot/tmp/upload')) {
}
}
-// publish stats as headers
+$last_pkg = ($_GET['last'] && $total > 0) ? reset($pkgs) : null
+publish_stats_headers($stats, $last_pkg);
-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");
-
-if (isset($_GET['last']) && $total > 0) {
- reset($pkgs);
- $last = current($pkgs);
- Header("X-BS-Package-Status: ".$last['type']);
-}
-
-$buildtime_total = $buildtime_total / 60;
-header(sprintf('X-BS-Buildtime: %d', round($buildtime_total)));
-
-$build_count = $build_count == 0 ? 1 : $build_count;
-$buildtime_avg = round($buildtime_total / $build_count, 2);
-header(sprintf('X-BS-Buildtime-Average: %5.2f', $buildtime_avg));
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">