]> git.mxchange.org Git - friendica.git/commitdiff
Use deferred tasks
authorMichael <heluecht@pirati.ca>
Thu, 21 Jul 2022 06:23:55 +0000 (06:23 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 21 Jul 2022 06:23:55 +0000 (06:23 +0000)
src/Protocol/ActivityPub/Processor.php
src/Protocol/ActivityPub/Queue.php
src/Worker/Cron.php
src/Worker/FetchMissingActivity.php

index 60793f80262db9db170817ceea1f94edebc8c881..fe7a4c5967aa1252270319364475e79d21c63d37 100644 (file)
@@ -284,9 +284,16 @@ class Processor
                        $recursion_depth = $activity['recursion-depth'] ?? 0;
                        Logger::notice('Parent not found. Try to refetch it.', ['parent' => $activity['reply-to-id'], 'recursion-depth' => $recursion_depth]);
                        if ($recursion_depth < 10) {
-                               self::fetchMissingActivity($activity['reply-to-id'], $activity, '', Receiver::COMPLETION_AUTO);
+                               $result = self::fetchMissingActivity($activity['reply-to-id'], $activity, '', Receiver::COMPLETION_AUTO);
+                               $fetch_by_worker = empty($result);
                        } else {
-                               Logger::notice('Recursion level is too high, fetching is done by worker.', ['parent' => $activity['reply-to-id'], 'recursion-depth' => $recursion_depth]);
+                               Logger::notice('Recursion level is too high.', ['parent' => $activity['reply-to-id'], 'recursion-depth' => $recursion_depth]);
+                               $activity['recursion-depth'] = 0;
+                               $fetch_by_worker = true;
+                       }
+
+                       if ($fetch_by_worker) {
+                               Logger::notice('Fetching is done by worker.', ['parent' => $activity['reply-to-id'], 'recursion-depth' => $recursion_depth]);
                                Worker::add(PRIORITY_HIGH, 'FetchMissingActivity', $activity['reply-to-id'], $activity, '', Receiver::COMPLETION_AUTO);
                                return [];
                        }
index c3605ebb64d3b425e2341573620450fefeb8dd19..c5cfd522ae227239b84b447e97666de0f3781403 100644 (file)
@@ -126,8 +126,16 @@ class Queue
                while ($entry = DBA::fetch($entries)) {
                        self::process($entry['id']);
                }
+       }
 
-               DBA::delete('inbox-entry', ["`received` < ?", DateTimeFormat::utc('now - 1 days')]);
+       /**
+        * Process all activities
+        *
+        * @return void
+        */
+       public static function clear()
+       {
+               DBA::delete('inbox-entry', ["`received` < ?", DateTimeFormat::utc('now - 2 days')]);
        }
 
        /**
index ee3fafe4bbea4c83db5dacf87dc120731a013f4f..68ad2180145b6be648cc64e5bc013c11c5a5b1ec 100644 (file)
@@ -89,8 +89,8 @@ class Cron
                        Tag::setLocalTrendingHashtags(24, 20);
                        Tag::setGlobalTrendingHashtags(24, 20);
 
-                       // Process pending posts in the queue
-                       Queue::processAll();
+                       // Remove old pending posts from the queue
+                       Queue::clear();
 
                        // Search for new contacts in the directory
                        if (DI::config()->get('system', 'synchronize_directory')) {
index 5aabe89ced7d2c687c0cdd2dddef2813b286b193..ceab8b7338430d4a9361be13b8c0cd348049f16b 100644 (file)
@@ -22,6 +22,7 @@
 namespace Friendica\Worker;
 
 use Friendica\Core\Logger;
+use Friendica\Core\Worker;
 use Friendica\Protocol\ActivityPub;
 use Friendica\Protocol\ActivityPub\Receiver;
 
@@ -35,6 +36,13 @@ class FetchMissingActivity
        {
                Logger::info('Start fetching missing activity', ['url' => $url]);
                $result = ActivityPub\Processor::fetchMissingActivity($url, $child, $relay_actor, $completion);
-               Logger::info('Finished fetching missing activity', ['url' => $url, 'result' => $result]);
+               if ($result) {
+                       Logger::info('Successfully fetched missing activity', ['url' => $url]);
+               } elseif (!Worker::defer()) {
+                       Logger::info('Activity could not be fetched', ['url' => $url]);
+                       // Possibly we should recursively remove child activities at this point.
+               } else {
+                       Logger::info('Fetching deferred', ['url' => $url]);
+               }
        }
 }