From 0f0f4bc2c7fb5ab429f06ddc1202a138478f107a Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 13 May 2022 07:31:00 +0000 Subject: [PATCH] New worker job for deliveries without a worker --- src/Worker/Cron.php | 3 +++ src/Worker/RequeuePosts.php | 44 +++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/Worker/RequeuePosts.php diff --git a/src/Worker/Cron.php b/src/Worker/Cron.php index 01c54fed1..e39ba24aa 100644 --- a/src/Worker/Cron.php +++ b/src/Worker/Cron.php @@ -95,6 +95,9 @@ class Cron // Clear cache entries Worker::add(PRIORITY_LOW, 'ClearCache'); + // Requeue posts from the post delivery entries + Worker::add(PRIORITY_MEDIUM, 'RequeuePosts'); + DI::config()->set('system', 'last_cron_hourly', time()); } diff --git a/src/Worker/RequeuePosts.php b/src/Worker/RequeuePosts.php new file mode 100644 index 000000000..787e5b071 --- /dev/null +++ b/src/Worker/RequeuePosts.php @@ -0,0 +1,44 @@ +. + * + */ + +namespace Friendica\Worker; + +use Friendica\Core\Logger; +use Friendica\Core\Worker; +use Friendica\Database\DBA; + +/** + * Requeue posts that are stuck in the post-delivery table without a matching delivery job. + * This should not happen in regular situations, this is a precaution. + */ +class RequeuePosts +{ + public static function execute() + { + $deliveries = DBA::p("SELECT `item-uri`.`uri` AS `inbox` FROM `post-delivery` INNER JOIN `item-uri` ON `item-uri`.`id` = `post-delivery`.`inbox-id` GROUP BY `inbox`"); + while ($delivery = DBA::fetch($deliveries)) { + if (Worker::add(PRIORITY_HIGH, 'APDelivery', '', 0, $delivery['inbox'], 0)) { + Logger::info('Missing APDelivery worker added for inbox', ['inbox' => $delivery['inbox']]); + } + } + DBA::close($deliveries); + } +}