]> git.mxchange.org Git - friendica.git/commitdiff
Individual defer limits per worker task
authorMichael <heluecht@pirati.ca>
Sun, 29 Oct 2023 12:51:26 +0000 (12:51 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 29 Oct 2023 12:51:26 +0000 (12:51 +0000)
src/Core/Worker.php
src/Worker/Contact/RevokeFollow.php
src/Worker/Contact/Unfollow.php
src/Worker/FetchMissingActivity.php

index 0c6b67f855d72e814f16dd875852e21e6e24e0bf..d7eaeb15ebcada0c2c8cd31bc2328661be03e609 100644 (file)
@@ -1379,10 +1379,11 @@ class Worker
        /**
         * Defers the current worker entry
         *
+        * @param int $worker_defer_limit Maximum defer limit 
         * @return boolean had the entry been deferred?
         * @throws \Exception
         */
-       public static function defer(): bool
+       public static function defer(int $worker_defer_limit = 0): bool
        {
                $queue = DI::app()->getQueue();
 
@@ -1395,6 +1396,10 @@ class Worker
 
                $max_level = DI::config()->get('system', 'worker_defer_limit');
 
+               if ($worker_defer_limit) {
+                       $max_level = min($worker_defer_limit, $max_level);
+               }
+
                $new_retrial = self::getNextRetrial($queue, $max_level);
 
                if ($new_retrial > $max_level) {
index 51116ac64f80084807f978a2727118ba70d69d26..714866f425c6144b28f71ff0bdb0649bde2dc20b 100644 (file)
@@ -29,6 +29,8 @@ use Friendica\Network\HTTPException;
 
 class RevokeFollow
 {
+       const WORKER_DEFER_LIMIT = 5;
+
        /**
         * Issue asynchronous follow revocation message to remote servers.
         * The local relationship has already been updated, so we can't use the user-specific contact
@@ -51,7 +53,7 @@ class RevokeFollow
                }
 
                if (!Protocol::revokeFollow($contact, $owner)) {
-                       Worker::defer();
+                       Worker::defer(self::WORKER_DEFER_LIMIT);
                }
        }
 }
index 20170be563be653f0982348216745ab3b1e00466..8956d882d918ddbc6981ea3f5c5a91a79a913089 100644 (file)
@@ -28,6 +28,8 @@ use Friendica\Model\User;
 
 class Unfollow
 {
+       const WORKER_DEFER_LIMIT = 5;
+
        /**
         * Issue asynchronous unfollow message to remote servers.
         * The local relationship has already been updated, so we can't use the user-specific contact.
@@ -51,7 +53,7 @@ class Unfollow
 
                $result = Protocol::unfollow($contact, $owner);
                if ($result === false) {
-                       Worker::defer();
+                       Worker::defer(self::WORKER_DEFER_LIMIT);
                }
        }
 }
index d48d834c672e1a4b8871420465d6744fc07ba539..4d1b23b0684200dda35aea391a14d3639f1780ee 100644 (file)
@@ -30,6 +30,8 @@ use Friendica\Protocol\ActivityPub\Receiver;
 
 class FetchMissingActivity
 {
+       const WORKER_DEFER_LIMIT = 5;
+
        /**
         * Fetch missing activities
         * @param string $url Contact URL
@@ -42,7 +44,7 @@ class FetchMissingActivity
                $result = ActivityPub\Processor::fetchMissingActivity($url, $child, $relay_actor, $completion);
                if ($result) {
                        Logger::info('Successfully fetched missing activity', ['url' => $url]);
-               } elseif (!Worker::defer()) {
+               } elseif (!Worker::defer(self::WORKER_DEFER_LIMIT)) {
                        Logger::info('Activity could not be fetched', ['url' => $url]);
 
                        // recursively delete all entries that belong to this worker task