New "Defunct" check

This commit is contained in:
Michael 2022-12-31 16:01:40 +00:00
parent dc528a020b
commit f022a49f9e
2 changed files with 42 additions and 2 deletions

View file

@ -164,6 +164,39 @@ class GServer
return DI::dba()->toArray($stmt);
}
/**
* Checks if the given server array is unreachable for a long time now
*
* @param integer $gsid
* @return boolean
*/
private static function defunctByArray(array $gserver): bool
{
return ($gserver['failed'] || in_array($gserver['network'], Protocol::FEDERATED)) &&
($gserver['last_contact'] >= $gserver['created']) &&
($gserver['last_contact'] < $gserver['last_failure']) &&
($gserver['last_contact'] < DateTimeFormat::utc('now - 90 days'));
}
/**
* Checks if the given server id is unreachable for a long time now
*
* @param integer $gsid
* @return boolean
*/
public static function defunct(int $gsid): bool
{
$gserver = DBA::selectFirst('gserver', ['url', 'next_contact', 'last_contact', 'last_failure', 'created', 'failed', 'network'], ['id' => $gsid]);
if (empty($gserver)) {
return false;
} else {
if (strtotime($gserver['next_contact']) < time()) {
Worker::add(Worker::PRIORITY_LOW, 'UpdateGServer', $gserver['url'], false);
}
return self::defunctByArray($gserver);
}
}
/**
* Checks if the given server id is reachable
*
@ -374,6 +407,9 @@ class GServer
'next_contact' => $next_update, 'network' => Protocol::PHANTOM, 'detection-method' => null],
['nurl' => Strings::normaliseLink($url)]);
Logger::info('Set failed status for existing server', ['url' => $url]);
if (self::defunctByArray($gserver)) {
Contact::update(['archive' => true], ['gsid' => $gserver['id']]);
}
return;
}
self::insert(['url' => $url, 'nurl' => Strings::normaliseLink($url),
@ -617,6 +653,11 @@ class GServer
$serverdata = self::detectNetworkViaContacts($url, $serverdata);
}
if (($serverdata['network'] == Protocol::PHANTOM) && in_array($serverdata['detection-method'], [self::DETECT_MANUAL, self::DETECT_BODY])) {
self::setFailure($url);
return false;
}
// Detect the directory type
$serverdata['directory-type'] = self::DT_NONE;

View file

@ -570,8 +570,7 @@ class Notifier
} elseif (!DI::config()->get('system', 'bulk_delivery')) {
$reachable = !GServer::reachableById($contact['gsid']);
} else {
// On bulk delivery we don't check the server status at this point
$reachable = true;
$reachable = !GServer::defunct($contact['gsid']);
}
if (!$reachable) {