From 9faad72ec06f7e5f1b884a44234465e564626b58 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 29 Oct 2023 12:51:26 +0000 Subject: [PATCH] Individual defer limits per worker task --- src/Core/Worker.php | 7 ++++++- src/Worker/Contact/RevokeFollow.php | 4 +++- src/Worker/Contact/Unfollow.php | 4 +++- src/Worker/FetchMissingActivity.php | 4 +++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Core/Worker.php b/src/Core/Worker.php index 0c6b67f85..d7eaeb15e 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -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) { diff --git a/src/Worker/Contact/RevokeFollow.php b/src/Worker/Contact/RevokeFollow.php index 51116ac64..714866f42 100644 --- a/src/Worker/Contact/RevokeFollow.php +++ b/src/Worker/Contact/RevokeFollow.php @@ -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); } } } diff --git a/src/Worker/Contact/Unfollow.php b/src/Worker/Contact/Unfollow.php index 20170be56..8956d882d 100644 --- a/src/Worker/Contact/Unfollow.php +++ b/src/Worker/Contact/Unfollow.php @@ -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); } } } diff --git a/src/Worker/FetchMissingActivity.php b/src/Worker/FetchMissingActivity.php index d48d834c6..4d1b23b06 100644 --- a/src/Worker/FetchMissingActivity.php +++ b/src/Worker/FetchMissingActivity.php @@ -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