summaryrefslogtreecommitdiffstats
path: root/lib.php
diff options
context:
space:
mode:
authorRomain d'Alverny <rda@mageia.org>2012-09-04 13:42:14 +0000
committerRomain d'Alverny <rda@mageia.org>2012-09-04 13:42:14 +0000
commited760b3ef9ed44d2346e4c9358e530af74dbe3ae (patch)
tree9c6bf97baefd1321d81c0bea02d3790a067e7c0f /lib.php
parent02b2daa157454c04a10bbf244cb673f71b9f80a4 (diff)
downloadpkgsubmit-ed760b3ef9ed44d2346e4c9358e530af74dbe3ae.tar
pkgsubmit-ed760b3ef9ed44d2346e4c9358e530af74dbe3ae.tar.gz
pkgsubmit-ed760b3ef9ed44d2346e4c9358e530af74dbe3ae.tar.bz2
pkgsubmit-ed760b3ef9ed44d2346e4c9358e530af74dbe3ae.tar.xz
pkgsubmit-ed760b3ef9ed44d2346e4c9358e530af74dbe3ae.zip
new publish_stats_headers() function
Diffstat (limited to 'lib.php')
-rw-r--r--lib.php36
1 files changed, 36 insertions, 0 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));
+}