Set the server status directly after transmission

This commit is contained in:
Michael 2023-01-01 17:34:05 +00:00
parent 8c60e853ca
commit f1bcf1ef66
5 changed files with 23 additions and 11 deletions

View File

@ -164,18 +164,15 @@ class Cron
*/ */
private static function deliverAPPosts() private static function deliverAPPosts()
{ {
$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()"); $deliveries = DBA::p("SELECT `item-uri`.`uri` AS `inbox`, MAX(`gsid`) AS `gsid`, MAX(`shared`) AS `shared`, 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) && $delivery['shared'] && !empty($delivery['gsid']) && GServer::isReachableById($delivery['gsid'])) {
$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;

View File

@ -361,12 +361,17 @@ class GServer
* Reset failed server status by gserver id * Reset failed server status by gserver id
* *
* @param int $gsid * @param int $gsid
* @param string $network
*/ */
public static function setReachableById(int $gsid) public static function setReachableById(int $gsid, string $network)
{ {
$gserver = DBA::selectFirst('gserver', ['url', 'failed', 'next_contact'], ['id' => $gsid]); $gserver = DBA::selectFirst('gserver', ['url', 'failed', 'next_contact', 'network'], ['id' => $gsid]);
if (DBA::isResult($gserver) && $gserver['failed']) { if (DBA::isResult($gserver) && $gserver['failed']) {
self::update(['failed' => false, 'last_contact' => DateTimeFormat::utcNow()], ['id' => $gsid]); $fields = ['failed' => false, 'last_contact' => DateTimeFormat::utcNow()];
if (!empty($network) && !in_array($gserver['network'], Protocol::FEDERATED)) {
$fields['network'] = $network;
}
self::update($fields, ['id' => $gsid]);
Logger::info('Reset failed status for server', ['url' => $gserver['url']]); Logger::info('Reset failed status for server', ['url' => $gserver['url']]);
if (strtotime($gserver['next_contact']) < time()) { if (strtotime($gserver['next_contact']) < time()) {

View File

@ -1040,7 +1040,7 @@ class DFRN
} }
if (!empty($contact['gsid'])) { if (!empty($contact['gsid'])) {
GServer::setReachableById($contact['gsid']); GServer::setReachableById($contact['gsid'], Protocol::DFRN);
} }
if (!empty($res->message)) { if (!empty($res->message)) {

View File

@ -2958,7 +2958,7 @@ class Diaspora
if (!empty($contact['gsid']) && (empty($return_code) || $postResult->isTimeout())) { if (!empty($contact['gsid']) && (empty($return_code) || $postResult->isTimeout())) {
GServer::setFailureById($contact['gsid']); GServer::setFailureById($contact['gsid']);
} elseif (!empty($contact['gsid']) && ($return_code >= 200) && ($return_code <= 299)) { } elseif (!empty($contact['gsid']) && ($return_code >= 200) && ($return_code <= 299)) {
GServer::setReachableById($contact['gsid']); GServer::setReachableById($contact['gsid'], Protocol::DIASPORA);
} }
Logger::notice('transmit: ' . $logid . '-' . $guid . ' to ' . $dest_url . ' returns: ' . $return_code); Logger::notice('transmit: ' . $logid . '-' . $guid . ' to ' . $dest_url . ' returns: ' . $return_code);

View File

@ -22,11 +22,13 @@
namespace Friendica\Util; namespace Friendica\Util;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\APContact; use Friendica\Model\APContact;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\GServer;
use Friendica\Model\ItemURI; use Friendica\Model\ItemURI;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses; use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses;
@ -398,6 +400,14 @@ class HTTPSignature
} }
DBA::update('inbox-status', $fields, ['url' => $url]); DBA::update('inbox-status', $fields, ['url' => $url]);
if (!empty($status['gsid'])) {
if ($success) {
GServer::setReachableById($status['gsid'], Protocol::ACTIVITYPUB);
} elseif ($status['shared']) {
GServer::setFailureById($status['gsid']);
}
}
} }
/** /**