From: Alan Date: Wed, 11 Oct 2023 05:07:27 +0000 (+0800) Subject: add queue sizes to server list X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=commitdiff_plain;h=7f7fa72b33109e3acd1ba3fdb024313f08d51a53 add queue sizes to server list --- diff --git a/DataObjects/Core_notify_server.php b/DataObjects/Core_notify_server.php index 198745b3..ac044ae9 100644 --- a/DataObjects/Core_notify_server.php +++ b/DataObjects/Core_notify_server.php @@ -17,6 +17,62 @@ class Pman_Core_DataObjects_Core_notify_server extends DB_DataObject public $is_active; public $last_send; + + + function applyFilters($q, $au, $roo) + { + if (isset($q['_with_queue_size'])) { + $this->addQueueSize(); + } + } + + + function addQueueSize() + { + // look for database links for server_id (which should find core_notify + others..) + $cn = get_class(DB_DataObject::factory('core_notify')); + $tables = array(); + foreach($this->databaseLinks() as $tbl => $kv) { + foreach($kv as $k=>$v) { + if ($v != 'core_notify_server:id') { + continue; + } + + $test = DB_DAtaObject::factory($tbl); + if (!is_a($test, $cn)) { + break; + } + $tables[] = $tbl; + } + } + if (empty($tables)) { + die("OOPS - no tables for notify_server references"); + } + $totals = array(); + foreach($tables as $t) { + $totals[] = " + COALESCE((SELECT + count(id) + FROM + $t + WHERE + server_id = core_notify_server.id + AND + sent < '1970-01-01' OR sent IS NULL + and + event_id = 0 + ),0) + "; + } + $this->selectAdd("(" . implode(" + ", $totals) . ") as in_queue "); + + + + + + } + + // most services should call this first.. function getCurrent($notify)