]> git.mxchange.org Git - friendica.git/commitdiff
Replace App with AppHelper in Worker classes
authorArt4 <art4@wlabs.de>
Fri, 8 Nov 2024 07:42:35 +0000 (07:42 +0000)
committerArt4 <art4@wlabs.de>
Fri, 8 Nov 2024 07:42:35 +0000 (07:42 +0000)
src/Core/Worker.php
src/Protocol/ActivityPub/Queue.php
src/Worker/Expire.php
src/Worker/FetchMissingActivity.php
src/Worker/Notifier.php
src/Worker/ProfileUpdate.php

index 8a8270bdb9bcf319481b3b9e42675da912c2aa70..6aa8d4331d0c57089dddb52cd0d3e9d0d20b7aa4 100644 (file)
@@ -533,7 +533,7 @@ class Worker
         */
        private static function execFunction(array $queue, string $funcname, array $argv, bool $method_call)
        {
-               $a = DI::app();
+               $appHelper = DI::apphelper();
 
                self::coolDown();
 
@@ -547,7 +547,7 @@ class Worker
                // For this reason the variables have to be initialized.
                DI::profiler()->reset();
 
-               $a->setQueue($queue);
+               $appHelper->setQueue($queue);
 
                $up_duration = microtime(true) - self::$up_start;
 
@@ -571,7 +571,7 @@ class Worker
 
                Logger::disableWorker();
 
-               $a->setQueue([]);
+               $appHelper->setQueue([]);
 
                $duration = (microtime(true) - $stamp);
 
@@ -830,7 +830,7 @@ class Worker
                                        return false;
                                } elseif ($max_idletime > 0) {
                                        Logger::debug('Maximum idletime not reached.', ['last' => $last_check, 'last-check' => $last_date, 'seconds' => $max_idletime, 'load' => $load, 'max_load' => $maxsysload, 'active_worker' => $active, 'max_worker' => $maxqueues]);
-                               }       
+                               }
                        }
                }
 
@@ -1371,20 +1371,20 @@ class Worker
         */
        public static function getRetrial(): int
        {
-               $queue = DI::app()->getQueue();
+               $queue = DI::apphelper()->getQueue();
                return $queue['retrial'] ?? 0;
        }
 
        /**
         * Defers the current worker entry
         *
-        * @param int $worker_defer_limit Maximum defer limit 
+        * @param int $worker_defer_limit Maximum defer limit
         * @return boolean had the entry been deferred?
         * @throws \Exception
         */
        public static function defer(int $worker_defer_limit = 0): bool
        {
-               $queue = DI::app()->getQueue();
+               $queue = DI::apphelper()->getQueue();
 
                if (empty($queue)) {
                        return false;
index 54bdee9dc00e8cdb91cf139e2cd2fec43dfa7052..678decb1cac24713fe3dfcba2df930844dded0f6 100644 (file)
@@ -192,7 +192,7 @@ class Queue
                }
 
                if (!empty($entry['wid'])) {
-                       $worker = DI::app()->getQueue();
+                       $worker = DI::apphelper()->getQueue();
                        $wid = $worker['id'] ?? 0;
                        if ($entry['wid'] != $wid) {
                                $workerqueue = DBA::selectFirst('workerqueue', ['pid'], ['id' => $entry['wid'], 'done' => false]);
index e7d77fdbd7afbc43f1480c4c1b6f7b047d3e3d5c..2193791229a34339a9d5c003f3883962e7726008 100644 (file)
@@ -21,7 +21,7 @@ class Expire
 {
        public static function execute($param = '', $hook_function = '')
        {
-               $a = DI::app();
+               $appHelper = DI::apphelper();
 
                Hook::loadHooks();
 
@@ -48,7 +48,7 @@ class Expire
                $r = DBA::select('user', ['uid', 'username'], ["`expire` != ?", 0]);
                while ($row = DBA::fetch($r)) {
                        Logger::info('Calling expiry', ['user' => $row['uid'], 'username' => $row['username']]);
-                       Worker::add(['priority' => $a->getQueueValue('priority'), 'created' => $a->getQueueValue('created'), 'dont_fork' => true],
+                       Worker::add(['priority' => $appHelper->getQueueValue('priority'), 'created' => $appHelper->getQueueValue('created'), 'dont_fork' => true],
                                'Expire', (int)$row['uid']);
                }
                DBA::close($r);
@@ -56,7 +56,7 @@ class Expire
                Logger::notice('calling hooks');
                foreach (Hook::getByName('expire') as $hook) {
                        Logger::info('Calling expire', ['hook' => $hook[1]]);
-                       Worker::add(['priority' => $a->getQueueValue('priority'), 'created' => $a->getQueueValue('created'), 'dont_fork' => true],
+                       Worker::add(['priority' => $appHelper->getQueueValue('priority'), 'created' => $appHelper->getQueueValue('created'), 'dont_fork' => true],
                                'Expire', 'hook', $hook[1]);
                }
 
index b5319c85fd2f6abcdb5a6d3ef687742766895422..7224f85cdb9f3bade1d907f7d2c7ebc79aeb9e51 100644 (file)
@@ -40,7 +40,7 @@ class FetchMissingActivity
                        Logger::info('Defer limit reached, activity could not be fetched', ['url' => $url]);
 
                        // recursively delete all entries that belong to this worker task
-                       $queue = DI::app()->getQueue();
+                       $queue = DI::apphelper()->getQueue();
                        if (!empty($queue['id'])) {
                                Queue::deleteByWorkerId($queue['id']);
                        }
index 73ff4685f84e5853c18911f358a5e0404962d8fa..256c6f6dd4e06d7a15fb4eab4eb2515af6430adc 100644 (file)
@@ -41,7 +41,7 @@ class Notifier
 {
        public static function execute(string $cmd, int $post_uriid, int $sender_uid = 0)
        {
-               $a = DI::app();
+               $appHelper = DI::apphelper();
 
                Logger::info('Invoked', ['cmd' => $cmd, 'target' => $post_uriid, 'sender_uid' => $sender_uid]);
 
@@ -69,7 +69,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' => Worker::PRIORITY_HIGH, 'created' => $a->getQueueValue('created'), 'dont_fork' => true],
+                               Worker::add(['priority' => Worker::PRIORITY_HIGH, 'created' => $appHelper->getQueueValue('created'), 'dont_fork' => true],
                                        'APDelivery', $cmd, $target_id, $inbox, $uid, $receivers, $post_uriid);
                        }
                } elseif ($cmd == Delivery::SUGGESTION) {
@@ -77,7 +77,7 @@ class Notifier
                        $uid = $suggest->uid;
                        $recipients[] = $suggest->cid;
                } elseif ($cmd == Delivery::REMOVAL) {
-                       return self::notifySelfRemoval($target_id, $a->getQueueValue('priority'), $a->getQueueValue('created'));
+                       return self::notifySelfRemoval($target_id, $appHelper->getQueueValue('priority'), $appHelper->getQueueValue('created'));
                } elseif ($cmd == Delivery::RELOCATION) {
                        $uid = $target_id;
 
@@ -162,7 +162,7 @@ class Notifier
                        Logger::info('Got post', ['guid' => $target_item['guid'], 'uri-id' => $target_item['uri-id'], 'network' => $target_item['network'], 'parent-network' => $parent['network'], 'thread-parent-network' => $thr_parent['network']]);
 
                        if (!self::isRemovalActivity($cmd, $owner, Protocol::ACTIVITYPUB)) {
-                               $apdelivery = self::activityPubDelivery($cmd, $target_item, $parent, $thr_parent, $a->getQueueValue('priority'), $a->getQueueValue('created'), $owner);
+                               $apdelivery = self::activityPubDelivery($cmd, $target_item, $parent, $thr_parent, $appHelper->getQueueValue('priority'), $appHelper->getQueueValue('created'), $owner);
                                $ap_contacts = $apdelivery['contacts'];
                                $delivery_queue_count += $apdelivery['count'];
                                // Restrict distribution to AP, when there are no permissions.
@@ -386,7 +386,7 @@ class Notifier
                if (!empty($target_item)) {
                        Logger::info('Calling hooks for ' . $cmd . ' ' . $target_id);
 
-                       Hook::fork($a->getQueueValue('priority'), 'notifier_normal', $target_item);
+                       Hook::fork($appHelper->getQueueValue('priority'), 'notifier_normal', $target_item);
 
                        Hook::callAll('notifier_end', $target_item);
 
@@ -424,7 +424,7 @@ class Notifier
         */
        private static function delivery(string $cmd, int $post_uriid, int $sender_uid, array $target_item, array $thr_parent, array $owner, bool $batch_delivery, bool $in_batch, array $contacts, array $ap_contacts, array $conversants = []): int
        {
-               $a = DI::app();
+               $appHelper = DI::apphelper();
                $delivery_queue_count = 0;
 
                if (!empty($target_item['verb']) && ($target_item['verb'] == Activity::ANNOUNCE)) {
@@ -511,10 +511,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->getQueueValue('priority'), [Worker::PRIORITY_HIGH, Worker::PRIORITY_MEDIUM])) {
-                               $deliver_options = ['priority' => $a->getQueueValue('priority'), 'dont_fork' => true];
+                       if (($contact['network'] == Protocol::DIASPORA) && in_array($appHelper->getQueueValue('priority'), [Worker::PRIORITY_HIGH, Worker::PRIORITY_MEDIUM])) {
+                               $deliver_options = ['priority' => $appHelper->getQueueValue('priority'), 'dont_fork' => true];
                        } else {
-                               $deliver_options = ['priority' => $a->getQueueValue('priority'), 'created' => $a->getQueueValue('created'), 'dont_fork' => true];
+                               $deliver_options = ['priority' => $appHelper->getQueueValue('priority'), 'created' => $appHelper->getQueueValue('created'), 'dont_fork' => true];
                        }
 
                        if (!empty($contact['gsid']) && DI::config()->get('system', 'bulk_delivery')) {
index 8490aad74e908f434e7bdd02c58d57de7968b5fb..fb8ecfd8572a9b60b1dd496cb90385a999867a09 100644 (file)
@@ -30,13 +30,13 @@ class ProfileUpdate {
                        return;
                }
 
-               $a = DI::app();
+               $appHelper = DI::apphelper();
 
                $inboxes = ActivityPub\Transmitter::fetchTargetInboxesforUser($uid);
 
                foreach ($inboxes as $inbox => $receivers) {
                        Logger::info('Profile update for user ' . $uid . ' to ' . $inbox .' via ActivityPub');
-                       Worker::add(['priority' => $a->getQueueValue('priority'), 'created' => $a->getQueueValue('created'), 'dont_fork' => true],
+                       Worker::add(['priority' => $appHelper->getQueueValue('priority'), 'created' => $appHelper->getQueueValue('created'), 'dont_fork' => true],
                                'APDelivery',
                                Delivery::PROFILEUPDATE,
                                0,