12 private const LOCK_KEY =
'sonet.eventlock';
13 private static Service|
null $instance =
null;
14 private static bool $isJobOn =
false;
15 private static string $hitId;
20 private function __construct()
22 self::$hitId = $this->generateHid();
35 self::$instance =
new self();
38 return self::$instance;
83 if ($this->getEventCollection()->isDuplicate(
$event))
88 $eventId = $this->saveToDb(
$event);
91 $this->getEventCollection()->push(
$event);
96 if (!in_array(
$type, EventDictionary::WORKGROUP_EVENTS_SUPPORTED,
true))
101 $event = EventService\Event\Factory::buildEvent(self::$hitId,
$type,
$data);
103 if ($this->getEventCollection()->isDuplicate(
$event))
108 $this->getEventCollection()->push(
$event);
111 private function handleLostEvents(): void
118 $events = EventTable::getLostEvents();
124 foreach ($events as $row)
126 $event = EventService\Event\Factory::buildEvent(
129 Main\Web\Json::decode($row[
'DATA']),
133 $this->getEventCollection()->push(
$event);
140 private function enableJob(): void
146 [ __CLASS__,
'proceedEvents' ],
151 self::$isJobOn =
true;
158 private function getEventCollection(): EventCollection
160 return EventCollection::getInstance();
168 private function saveToDb(Event
$event): int
172 $res = EventTable::add([
173 'HID' => self::$hitId,
174 'TYPE' =>
$event->getType(),
175 'DATA' => Main\Web\Json::encode(
$event->getData()),
177 'PROCESSED' => Main\Type\DateTime::createFromTimestamp(0),
180 catch (\Exception $e)
185 return (
int)
$res->getId();
191 private function done(): void
193 $ids = $this->getEventCollection()->getEventsId();
199 EventTable::markProcessed([
209 private function generateHid(): string
211 return sha1(microtime(
true) . mt_rand(10000, 99999));
static getConnection($name="")