Merge pull request #12592 from annando/server-status

Set the server status directly after transmission
This commit is contained in:
Hypolite Petovan 2023-01-01 12:42:18 -05:00 committed by GitHub
commit 50ef24cb14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 11 deletions

View File

@ -164,18 +164,15 @@ class Cron
*/
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)) {
if ($delivery['failed'] > 0) {
Logger::info('Removing failed deliveries', ['inbox' => $delivery['inbox'], 'failed' => $delivery['failed']]);
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']);
Logger::info('Directly deliver inbox', ['inbox' => $delivery['inbox'], 'result' => $result['success']]);
if (!$result['success']) {
GServer::setFailureById($delivery['gsid']);
}
continue;
} elseif ($delivery['failed'] < 3) {
$priority = Worker::PRIORITY_HIGH;

View File

@ -360,13 +360,18 @@ class GServer
/**
* 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']) {
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']]);
if (strtotime($gserver['next_contact']) < time()) {

View File

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

View File

@ -2958,7 +2958,7 @@ class Diaspora
if (!empty($contact['gsid']) && (empty($return_code) || $postResult->isTimeout())) {
GServer::setFailureById($contact['gsid']);
} 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);

View File

@ -22,11 +22,13 @@
namespace Friendica\Util;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Database\Database;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\APContact;
use Friendica\Model\Contact;
use Friendica\Model\GServer;
use Friendica\Model\ItemURI;
use Friendica\Model\User;
use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses;
@ -398,6 +400,14 @@ class HTTPSignature
}
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']);
}
}
}
/**