Commit 9a8e053f authored by dmorley's avatar dmorley

use meta table for status rather than a status table

parent 0127edc7
......@@ -49,4 +49,4 @@ while ($entry = $dirh->read()) {
);
}
updateStatus('backup_data', date('Y-m-d H:i:s'));
updateMeta('backup');
CREATE TABLE status (
CREATE TABLE meta (
id serial8 UNIQUE PRIMARY KEY,
masterversions_updated timestamp,
monthlystats_updated timestamp,
pods_updated timestamp,
pods_update_runtime int,
geodb_updated timestamp,
cacert_updated timestamp,
federation_crawldate timestamp,
backup_data timestamp,
date_updated timestamp DEFAULT current_timestamp
name text,
value text,
date_created timestamp DEFAULT current_timestamp
);
......@@ -96,25 +96,9 @@ CREATE TABLE masterversions (
date_checked timestamp DEFAULT current_timestamp
);
CREATE TABLE monthlystats (
CREATE TABLE meta (
id serial8 UNIQUE PRIMARY KEY,
total_users int,
total_posts int,
total_comments int,
total_pods int,
total_uptime int,
date_checked timestamp DEFAULT current_timestamp
);
CREATE TABLE status (
id serial8 UNIQUE PRIMARY KEY,
masterversions_updated timestamp,
monthlystats_updated timestamp,
pods_updated timestamp,
pods_update_runtime int,
geodb_updated timestamp,
cacert_updated timestamp,
federation_crawldate timestamp,
backup_data timestamp,
date_updated timestamp DEFAULT current_timestamp
name text,
value text,
date_created timestamp DEFAULT current_timestamp
);
......@@ -84,4 +84,4 @@ foreach ($softwares as $software => $details) {
printf('%s:%s:%s ', $software, $masterversion, $devlastcommit ?: 'n/a');
}
updateStatus('masterversions_updated', date('Y-m-d H:i:s'));
updateMeta('masterversions_updated');
......@@ -55,4 +55,4 @@ foreach ($monthly_totals as $monthly) {
}
}
updateStatus('monthlystats_updated', date('Y-m-d H:i:s'));
updateMeta('monthlystats');
......@@ -54,4 +54,4 @@ foreach ($results as $result) {
echo exec("php-cgi add.php domain={$result}") . "\r\n";
}
updateStatus('federation_crawldate', date('Y-m-d H:i:s'));
updateMeta('federation_crawldate');
......@@ -55,7 +55,7 @@ try {
$sql .= ' WHERE status = ? ORDER BY id';
$pods = R::getAll($sql, [PodStatus::SYSTEM_DELETED]);
} elseif (is_cli()) {
$sql .= ' WHERE status < ? ORDER BY id';
$sql .= ' WHERE status < ? ORDER BY id LIMIT 9';
$pods = R::getAll($sql, [PodStatus::PAUSED]);
}
} catch (\RedBeanPHP\RedException $e) {
......@@ -430,7 +430,7 @@ foreach ($pods as $pod) {
echo $newline;
}
updateStatus('pods_updated', date('Y-m-d H:i:s'));
updateMeta('pods_updated');
$time_end = microtime(true);
$execution_time = ($time_end - $time_start)/60;
updateStatus('pods_update_runtime', round($execution_time));
updateMeta('pods_update_runtime', round($execution_time));
......@@ -23,17 +23,17 @@ $simpleview = !($mapview || $podmin || $podminedit || $statsview);
$fullview = false;
try {
$dbstatus = R::getRow('
SELECT pods_updated
FROM status
WHERE pods_updated is not null
$dbstatus = R::getRow("
SELECT date_created
FROM meta
WHERE name = 'pods_updated'
ORDER BY id DESC
LIMIT 1
');
");
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
}
$pods_updated = $dbstatus['pods_updated'];
$pods_updated = $dbstatus['date_created'];
?>
<!doctype html>
......@@ -153,7 +153,7 @@ $navs = [
</div>
</main>
<footer class="ml-3 text-muted">
<small>Data refreshed <?php echo Carbon::createFromFormat('Y-m-d H:i:s', $pods_updated)->diffForHumans(); ?></small>
<small>Data refreshed <?php echo Carbon::createFromFormat('Y-m-d H:i:s.u', $pods_updated)->diffForHumans(); ?></small>
</footer>
<input type="hidden" name="input" value="<?php echo $input ?>"/>
<script src="node_modules/jquery/dist/jquery.min.js"></script>
......
......@@ -213,15 +213,16 @@ function debugToConsole($data): void
}
/**
* Update status table
* Update meta table
*
* @param string
*/
function updateStatus($colname, $value = null)
function updateMeta($name, $value = '1')
{
try {
$u = R::dispense('status');
$u[$colname] = $value;
$u = R::dispense('meta');
$u['name'] = $name;
$u['value'] = $value;
R::store($u);
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
......
......@@ -8,28 +8,28 @@ use Carbon\Carbon;
use RedBeanPHP\R;
try {
$updbstatus = R::getRow('
SELECT pods_updated
FROM status
WHERE pods_updated is not null
$updbstatus = R::getRow("
SELECT date_created
FROM meta
WHERE name = 'pods_updated'
ORDER BY id DESC
LIMIT 1
');
");
} catch (\RedBeanPHP\RedException $e) {
die('Status Red Error in SQL query: ' . $e->getMessage());
}
try {
$durdbstatus = R::getRow('
SELECT pods_update_runtime
FROM status
WHERE pods_update_runtime is not null
$durdbstatus = R::getRow("
SELECT value
FROM meta
WHERE name = 'pods_update_runtime'
ORDER BY id DESC
LIMIT 1
');
");
} catch (\RedBeanPHP\RedException $e) {
die('Status Red Error in SQL query: ' . $e->getMessage());
}
$pods_updated_stats = Carbon::createFromFormat('Y-m-d H:i:s', $updbstatus['pods_updated'])->diffInMinutes();
$pods_updated_stats = Carbon::createFromFormat('Y-m-d H:i:s.u', $updbstatus['date_created'])->diffInMinutes();
echo "<small>";
if ($pods_updated_stats < 120) {
echo "System status is Green<br>";
......@@ -38,5 +38,5 @@ if ($pods_updated_stats < 120) {
}
echo "Last Update was " . $pods_updated_stats . " minutes<br>";
echo "Last Update run duration was " . $durdbstatus['pods_update_runtime'] . " minutes";
echo "Last Update run duration was " . $durdbstatus['value'] . " minutes";
echo "</small>";
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment