952 days continuous production uptime, 40k+ tp/s single node. Original corpo Bitbucket history not included — clean archive commit.
167 lines
5.3 KiB
PHP
167 lines
5.3 KiB
PHP
<?php
|
|
/**
|
|
* gacSystemEvents class
|
|
* ---------------------
|
|
* This class is for processing system events:
|
|
* -- Broker Events (instantiation, forks, events, etc.)
|
|
* -- Audit Events
|
|
* -- Journaling Events
|
|
*
|
|
* This class instantiates it's own copy of gacAdminClientIn for publishing messages to the AdminIN broker. As such,
|
|
* this class can be safely instantiated from any Namaste environment.
|
|
*
|
|
* @author mike@givvingassistant.org
|
|
* @version 1.0
|
|
*
|
|
* HISTORY:
|
|
* ========
|
|
* 08-16-17 mks CORE-500: initial coding
|
|
* 03-02-18 mks CORE-680: deprecated trace logging
|
|
* 08-02-18 mks CORE-774: PHP7.2 exception handling
|
|
* 01-08-20 mks DB-150: PHP7.4 member type-casting
|
|
*/
|
|
|
|
class gacSystemEvents extends gacMongoDB
|
|
{
|
|
private ?gacWorkQueueClient $aiClient;
|
|
private string $res = 'cSEV: ';
|
|
|
|
|
|
/**
|
|
* gacSystemEvents constructor
|
|
*
|
|
* The constructor takes an optional parameter:
|
|
*
|
|
* $_meta -- the meta data as received by the broker event
|
|
*
|
|
* If the meta parameters is empty, the assumption is that this class was instantiated client-side
|
|
* respective to the admin broker and we're preparing a publish event.
|
|
*
|
|
* The responsibilities of the constructor are basically to instantiate the class for pending requests.
|
|
*
|
|
* @author mike@givingassistant.com
|
|
* @version 1.0
|
|
*
|
|
* @param null $_meta
|
|
*
|
|
*
|
|
* HISTORY:
|
|
* ========
|
|
* 08-17-17 mks CORE-500: original coding
|
|
* 10-24-18 mks DB-57: mod for the meta data template override
|
|
*
|
|
*/
|
|
public function __construct($_meta = null)
|
|
{
|
|
if (empty($_meta)) {
|
|
$_meta = [
|
|
META_TEMPLATE => TEMPLATE_CLASS_SYS_EVENTS,
|
|
META_SESSION_DAEMON => 1
|
|
];
|
|
}
|
|
// sometimes I forget to replace the class template in the meta data that initiated the system event...
|
|
if ($_meta[META_TEMPLATE] != TEMPLATE_CLASS_SYS_EVENTS) $_meta[META_TEMPLATE] = TEMPLATE_CLASS_SYS_EVENTS;
|
|
try {
|
|
parent::__construct($_meta);
|
|
} catch (Throwable $t) {
|
|
$hdr = basename(__METHOD__) . AT . __LINE__ . COLON;
|
|
$msg = ERROR_THROWABLE_EXCEPTION . COLON . $t->getMessage();
|
|
@handleExceptionMessaging($hdr, $msg, $this->eventMessages, true);
|
|
$this->state = STATE_FRAMEWORK_FAIL;
|
|
$this->status = false;
|
|
return;
|
|
}
|
|
if (!$this->status) {
|
|
$msg = ERROR_FAILED_TO_INSTANTIATE . STRING_CLASS_MONGO;
|
|
if (isset($this->logger) and $this->logger->available)
|
|
$this->logger->warn($msg);
|
|
else
|
|
consoleLog($this->res, CON_ERROR, $msg);
|
|
$this->eventMessages[] = $msg;
|
|
return;
|
|
}
|
|
$this->aiClient = null;
|
|
$this->class = get_class($this);
|
|
}
|
|
|
|
|
|
/**
|
|
* fetchRecordBySessionGUID() -- public method
|
|
*
|
|
* This session-events class function requires a single input parameter:
|
|
*
|
|
* $_sessionGUID -- this is the session GUID, unique by definition, that we'll use to fetch the sys-event record
|
|
*
|
|
* The method assumes (because it was validated by the adminOut broker that called this method) that the GUID is valid.
|
|
* We'll exec a schema-fetch based on the query build to filter by the session GUID. On success, the entire record will
|
|
* populated in the current data object. Otherwise error messages and such.
|
|
*
|
|
* The function returns type void - success or failure can be tested by the class state/status.
|
|
*
|
|
*
|
|
* @author mike@givingassistant.org
|
|
* @version 1.0
|
|
*
|
|
* @param string $_sessionGUID
|
|
*
|
|
*
|
|
* HISTORY:
|
|
* ========
|
|
* 10-20-20 mks DB-168: original coding
|
|
*
|
|
*/
|
|
public function fetchRecordBySessionGUID(string $_sessionGUID):void
|
|
{
|
|
$query = [STRING_QUERY_DATA => [ SYSTEM_EVENT_FK_SESSION_GUID => [OPERAND_NULL => [OPERATOR_EQ => [$_sessionGUID]]]]];
|
|
$this->_fetchRecords($query);
|
|
if (!$this->status) {
|
|
$this->eventMessages[] = ERROR_NOSQL_FETCH;
|
|
consoleLog($this->res, CON_ERROR, sprintf(ERROR_MDB_FETCH_FAIL, TEMPLATE_CLASS_SYS_EVENTS) . SYSTEM_EVENT_FK_SESSION_GUID);
|
|
} elseif ($this->count != 1) {
|
|
$this->eventMessages[] = ERROR_FETCH;
|
|
$this->logger->warn(sprintf(ERROR_DATA_RECORD_COUNT,1, $this->count));
|
|
$this->logger->warn(json_encode($query));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* __clone() -- public method
|
|
*
|
|
* Silently disallows cloning of the object
|
|
*
|
|
* @author mike@givingassistant.org
|
|
* @version 1.0
|
|
*
|
|
* @return null
|
|
*
|
|
* HISTORY:
|
|
* ========
|
|
* 08-17-15 mks CORE-500: original coding
|
|
*
|
|
*/
|
|
private function __clone()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
|
|
/**
|
|
* __destruct() -- public method
|
|
*
|
|
* As of PHP 5.3.10, destructors are not run on shutdowns caused by fatal errors - since the destructor is
|
|
* now registered in the constructor method, recovery and/or clean-up efforts should go into this method.
|
|
*
|
|
* @author mike@givingassistant.org
|
|
* @version 1.0
|
|
*
|
|
* HISTORY:
|
|
* ========
|
|
* 08-17-15 mks CORE-500: original coding
|
|
*
|
|
*/
|
|
public function __destruct()
|
|
{
|
|
//do nothing
|
|
}
|
|
} |