]> git.mxchange.org Git - friendica.git/commitdiff
Getter/Setter for queue
authorMichael <heluecht@pirati.ca>
Sat, 24 Jul 2021 22:08:33 +0000 (22:08 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 24 Jul 2021 22:08:33 +0000 (22:08 +0000)
src/App.php
src/Core/Worker.php
src/Worker/Expire.php
src/Worker/Notifier.php
src/Worker/ProfileUpdate.php

index d71acef63221e5dc341f3be7633ff61dea02f2c1..9e2bb0d22f033448f611f2751ee0b8a729c8f126 100644 (file)
@@ -69,11 +69,11 @@ class App
        public $videowidth              = 425;
        public $videoheight             = 350;
        public $theme_events_in_profile = true;
-       public $queue;
 
-       private $timezone = '';
+       private $timezone      = '';
        private $profile_owner = 0;
        private $contact_id    = 0;
+       private $queue         = [];
 
        /**
         * @var App\Mode The Mode of the Application
@@ -133,8 +133,8 @@ class App
        /**
         * Set the profile owner ID
         *
-        * @param int $owner_id 
-        * @return void 
+        * @param int $owner_id
+        * @return void
         */
        public function setProfileOwner(int $owner_id)
        {
@@ -144,7 +144,7 @@ class App
        /**
         * Get the profile owner ID
         *
-        * @return int 
+        * @return int
         */
        public function getProfileOwner():int
        {
@@ -153,9 +153,9 @@ class App
 
        /**
         * Set the contact ID
-        * 
-        * @param int $contact_id 
-        * @return void 
+        *
+        * @param int $contact_id
+        * @return void
         */
        public function setContactId(int $contact_id)
        {
@@ -165,7 +165,7 @@ class App
        /**
         * Get the contact ID
         *
-        * @return int 
+        * @return int
         */
        public function getContactId():int
        {
@@ -174,9 +174,9 @@ class App
 
        /**
         * Set the timezone
-        * 
-        * @param int $timezone 
-        * @return void 
+        *
+        * @param int $timezone
+        * @return void
         */
        public function setTimeZone(string $timezone)
        {
@@ -186,13 +186,28 @@ class App
        /**
         * Get the timezone
         *
-        * @return int 
+        * @return int
         */
        public function getTimeZone():string
        {
                return $this->timezone;
        }
 
+       public function setQueue(array $queue)
+       {
+               $this->queue = $queue;
+       }
+
+       public function getQueue()
+       {
+               return $this->queue ?? [];
+       }
+
+       public function getQueueValue(string $index)
+       {
+               return $this->queue[$index] ?? null;
+       }
+
        /**
         * Returns the current config cache of this node
         *
index f21513f33c33c72f2f71cae0b91189b5bdda1577..824275fa7478ee68da237db23c721e742c337df0 100644 (file)
@@ -446,7 +446,7 @@ class Worker
                        $queue['priority'] = PRIORITY_MEDIUM;
                }
 
-               $a->queue = $queue;
+               $a->setQueue($queue);
 
                $up_duration = microtime(true) - self::$up_start;
 
@@ -462,7 +462,7 @@ class Worker
 
                Logger::disableWorker();
 
-               unset($a->queue);
+               $a->setQueue([]);
 
                $duration = (microtime(true) - $stamp);
 
@@ -831,7 +831,7 @@ class Worker
                $stamp = (float)microtime(true);
 
                $queues = DBA::p("SELECT `process`.`pid`, COUNT(`workerqueue`.`pid`) AS `entries` FROM `process`
-                       LEFT JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid` AND NOT `workerqueue`.`done` 
+                       LEFT JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid` AND NOT `workerqueue`.`done`
                        GROUP BY `process`.`pid`");
                while ($queue = DBA::fetch($queues)) {
                        $ids[$queue['pid']] = $queue['entries'];
@@ -1351,12 +1351,12 @@ class Worker
         */
        public static function defer()
        {
-               if (empty(DI::app()->queue)) {
+               $queue = DI::app()->getQueue();
+
+               if (empty($queue)) {
                        return false;
                }
 
-               $queue = DI::app()->queue;
-
                $retrial = $queue['retrial'];
                $id = $queue['id'];
                $priority = $queue['priority'];
@@ -1587,7 +1587,7 @@ class Worker
                } else {
                        Logger::info('We are outside the maintenance window', ['current' => date('H:i:s', $current), 'start' => date('H:i:s', $start), 'end' => date('H:i:s', $end)]);
                }
-               
+
                return $execute;
        }
 }
index d3b895f440dc44ea6f76cc437ee3cf1ce1b6da7a..d64a63a843aef47d16fdc503f4e53ac6a5383617 100644 (file)
@@ -62,7 +62,7 @@ class Expire
                $r = DBA::p("SELECT `uid`, `username` FROM `user` WHERE `expire` != 0");
                while ($row = DBA::fetch($r)) {
                        Logger::info('Calling expiry', ['user' => $row['uid'], 'username' => $row['username']]);
-                       Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true],
+                       Worker::add(['priority' => $a->getQueueValue('priority'), 'created' => $a->getQueueValue('created'), 'dont_fork' => true],
                                'Expire', (int)$row['uid']);
                }
                DBA::close($r);
@@ -70,7 +70,7 @@ class Expire
                Logger::notice('calling hooks');
                foreach (Hook::getByName('expire') as $hook) {
                        Logger::info('Calling expire', ['hook' => $hook[1]]);
-                       Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true],
+                       Worker::add(['priority' => $a->getQueueValue('priority'), 'created' => $a->getQueueValue('created'), 'dont_fork' => true],
                                'Expire', 'hook', $hook[1]);
                }
 
index 60ae65385520763d98463b7fb5bf26dac6f21a04..bec0c55f116ec72df4b7d41df56007cfd2e2bc83 100644 (file)
@@ -86,7 +86,7 @@ class Notifier
                        foreach ($inboxes as $inbox => $receivers) {
                                $ap_contacts = array_merge($ap_contacts, $receivers);
                                Logger::info('Delivery via ActivityPub', ['cmd' => $cmd, 'target' => $target_id, 'inbox' => $inbox]);
-                               Worker::add(['priority' => PRIORITY_HIGH, 'created' => $a->queue['created'], 'dont_fork' => true],
+                               Worker::add(['priority' => PRIORITY_HIGH, 'created' => $a->getQueueValue('created'), 'dont_fork' => true],
                                        'APDelivery', $cmd, $target_id, $inbox, $uid, $receivers, $post_uriid);
                        }
                } elseif ($cmd == Delivery::SUGGESTION) {
@@ -94,7 +94,7 @@ class Notifier
                        $uid = $suggest->uid;
                        $recipients[] = $suggest->cid;
                } elseif ($cmd == Delivery::REMOVAL) {
-                       return self::notifySelfRemoval($target_id, $a->queue['priority'], $a->queue['created']);
+                       return self::notifySelfRemoval($target_id, $a->getQueueValue('priority'), $a->getQueueValue('created'));
                } elseif ($cmd == Delivery::RELOCATION) {
                        $uid = $target_id;
 
@@ -182,7 +182,7 @@ class Notifier
                        Logger::log('GUID: ' . $target_item["guid"] . ': Parent is ' . $parent['network'] . '. Thread parent is ' . $thr_parent['network'], Logger::DEBUG);
 
                        if (!self::isRemovalActivity($cmd, $owner, Protocol::ACTIVITYPUB)) {
-                               $apdelivery = self::activityPubDelivery($cmd, $target_item, $parent, $thr_parent, $a->queue['priority'], $a->queue['created'], $owner);
+                               $apdelivery = self::activityPubDelivery($cmd, $target_item, $parent, $thr_parent, $a->getQueueValue('priority'), $a->getQueueValue('created'), $owner);
                                $ap_contacts = $apdelivery['contacts'];
                                $delivery_queue_count += $apdelivery['count'];
                        }
@@ -339,7 +339,7 @@ class Notifier
 
                                if ((intval($parent['forum_mode']) == 1) && !$top_level && ($cmd !== Delivery::UPLINK)
                                        && ($target_item['verb'] != Activity::ANNOUNCE)) {
-                                       Worker::add($a->queue['priority'], 'Notifier', Delivery::UPLINK, $post_uriid, $sender_uid);
+                                       Worker::add($a->getQueueValue('priority'), 'Notifier', Delivery::UPLINK, $post_uriid, $sender_uid);
                                }
 
                                foreach ($items as $item) {
@@ -492,7 +492,7 @@ class Notifier
                if (!empty($target_item)) {
                        Logger::log('Calling hooks for ' . $cmd . ' ' . $target_id, Logger::DEBUG);
 
-                       Hook::fork($a->queue['priority'], 'notifier_normal', $target_item);
+                       Hook::fork($a->getQueueValue('priority'), 'notifier_normal', $target_item);
 
                        Hook::callAll('notifier_end', $target_item);
 
@@ -581,10 +581,10 @@ class Notifier
                        // Situation is that sometimes Friendica servers receive Friendica posts over the Diaspora protocol first.
                        // The conversion in Markdown reduces the formatting, so these posts should arrive after the Friendica posts.
                        // This is only important for high and medium priority tasks and not for Low priority jobs like deletions.
-                       if (($contact['network'] == Protocol::DIASPORA) && in_array($a->queue['priority'], [PRIORITY_HIGH, PRIORITY_MEDIUM])) {
-                               $deliver_options = ['priority' => $a->queue['priority'], 'dont_fork' => true];
+                       if (($contact['network'] == Protocol::DIASPORA) && in_array($a->getQueueValue('priority'), [PRIORITY_HIGH, PRIORITY_MEDIUM])) {
+                               $deliver_options = ['priority' => $a->getQueueValue('priority'), 'dont_fork' => true];
                        } else {
-                               $deliver_options = ['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true];
+                               $deliver_options = ['priority' => $a->getQueueValue('priority'), 'created' => $a->getQueueValue('created'), 'dont_fork' => true];
                        }
 
                        if (Worker::add($deliver_options, 'Delivery', $cmd, $post_uriid, (int)$contact['id'], $sender_uid)) {
@@ -631,7 +631,7 @@ class Notifier
                        Logger::info('Activating internal PuSH', ['item' => $target_id]);
 
                        // Handling the pubsubhubbub requests
-                       PushSubscriber::publishFeed($owner['uid'], $a->queue['priority']);
+                       PushSubscriber::publishFeed($owner['uid'], $a->getQueueValue('priority'));
                }
                return $delivery_queue_count;
        }
index c5096636178c27c2cafcb37a9802383fa5c1916c..e9e9afe8d2c9e11c2be988d600f8d06605388626 100644 (file)
@@ -42,7 +42,7 @@ class ProfileUpdate {
 
                foreach ($inboxes as $inbox => $receivers) {
                        Logger::log('Profile update for user ' . $uid . ' to ' . $inbox .' via ActivityPub', Logger::DEBUG);
-                       Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true],
+                       Worker::add(['priority' => $a->getQueueValue('priority'), 'created' => $a->getQueueValue('created'), 'dont_fork' => true],
                                'APDelivery', Delivery::PROFILEUPDATE, 0, $inbox, $uid, $receivers);
                }