Use server id on direct delivery

This commit is contained in:
Michael 2023-01-01 15:13:44 +00:00
parent 6bc9754b24
commit 7307646cf8

View file

@ -164,16 +164,18 @@ class Cron
*/ */
private static function deliverAPPosts() private static function deliverAPPosts()
{ {
$deliveries = DBA::p("SELECT `item-uri`.`uri` AS `inbox`, MAX(`failed`) AS `failed` FROM `post-delivery` INNER JOIN `item-uri` ON `item-uri`.`id` = `post-delivery`.`inbox-id` GROUP BY `inbox` ORDER BY RAND()"); $deliveries = DBA::p("SELECT `item-uri`.`uri` AS `inbox`, MAX(`gsid`) AS `gsid`, MAX(`failed`) AS `failed` FROM `post-delivery` INNER JOIN `item-uri` ON `item-uri`.`id` = `post-delivery`.`inbox-id` LEFT JOIN `inbox-status` ON `inbox-status`.`url` = `item-uri`.`uri` GROUP BY `inbox` ORDER BY RAND()");
while ($delivery = DBA::fetch($deliveries)) { while ($delivery = DBA::fetch($deliveries)) {
if ($delivery['failed'] > 0) { if ($delivery['failed'] > 0) {
Logger::info('Removing failed deliveries', ['inbox' => $delivery['inbox'], 'failed' => $delivery['failed']]); Logger::info('Removing failed deliveries', ['inbox' => $delivery['inbox'], 'failed' => $delivery['failed']]);
Post\Delivery::removeFailed($delivery['inbox']); Post\Delivery::removeFailed($delivery['inbox']);
} }
if (($delivery['failed'] == 0) && !empty($delivery['gsid']) && GServer::isReachableById($delivery['gsid'])) {
if ($delivery['failed'] == 0) {
$result = ActivityPub\Delivery::deliver($delivery['inbox']); $result = ActivityPub\Delivery::deliver($delivery['inbox']);
Logger::info('Directly deliver inbox', ['inbox' => $delivery['inbox'], 'result' => $result['success']]); Logger::info('Directly deliver inbox', ['inbox' => $delivery['inbox'], 'result' => $result['success']]);
if (!$result['success']) {
GServer::setFailureById($delivery['gsid']);
}
continue; continue;
} elseif ($delivery['failed'] < 3) { } elseif ($delivery['failed'] < 3) {
$priority = Worker::PRIORITY_HIGH; $priority = Worker::PRIORITY_HIGH;