mirror of
https://github.com/friendica/friendica
synced 2025-05-19 13:44:10 +02:00
workerqueue now has a "command" field
This commit is contained in:
parent
aa4372447a
commit
edbdfbae6b
7 changed files with 145 additions and 55 deletions
|
@ -63,6 +63,9 @@ class Cron
|
|||
// Update contact information
|
||||
Worker::add(PRIORITY_LOW, 'UpdatePublicContacts');
|
||||
|
||||
// Update server information
|
||||
Worker::add(PRIORITY_LOW, 'UpdateGServers');
|
||||
|
||||
// run the process to update server directories in the background
|
||||
Worker::add(PRIORITY_LOW, 'UpdateServerDirectories');
|
||||
|
||||
|
@ -103,8 +106,6 @@ class Cron
|
|||
// update nodeinfo data
|
||||
Worker::add(PRIORITY_LOW, 'NodeInfo');
|
||||
|
||||
Worker::add(PRIORITY_LOW, 'UpdateGServers');
|
||||
|
||||
// Repair entries in the database
|
||||
Worker::add(PRIORITY_LOW, 'RepairDatabase');
|
||||
|
||||
|
|
|
@ -32,18 +32,19 @@ class UpdateGServer
|
|||
* @param string $server_url Server URL
|
||||
* @param boolean $only_nodeinfo Only use nodeinfo for server detection
|
||||
*/
|
||||
public static function execute(string $server_url, bool $only_nodeinfo = false)
|
||||
public static function execute(string $server_url, bool $only_nodeinfo = false, bool $force = false)
|
||||
{
|
||||
if (empty($server_url)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$server_url = filter_var($server_url, FILTER_SANITIZE_URL);
|
||||
if (substr(Strings::normaliseLink($server_url), 0, 7) != 'http://') {
|
||||
$filtered = filter_var($server_url, FILTER_SANITIZE_URL);
|
||||
if (substr(Strings::normaliseLink($filtered), 0, 7) != 'http://') {
|
||||
GServer::setFailure($filtered);
|
||||
return;
|
||||
}
|
||||
|
||||
$ret = GServer::check($server_url, '', false, $only_nodeinfo);
|
||||
Logger::info('Updated gserver', ['url' => $server_url, 'result' => $ret]);
|
||||
$ret = GServer::check($filtered, '', $force, $only_nodeinfo);
|
||||
Logger::info('Updated gserver', ['url' => $filtered, 'result' => $ret]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,34 +24,36 @@ namespace Friendica\Worker;
|
|||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\GServer;
|
||||
|
||||
class UpdateGServers
|
||||
{
|
||||
/**
|
||||
* Updates the first 250 servers
|
||||
* Updates up to 100 servers
|
||||
*/
|
||||
public static function execute()
|
||||
{
|
||||
$gservers = DBA::p("SELECT `url`, `created`, `last_failure`, `last_contact` FROM `gserver` ORDER BY rand()");
|
||||
$updating = Worker::countWorkersByCommand('UpdateGServer');
|
||||
$limit = 100 - $updating;
|
||||
if ($limit <= 0) {
|
||||
Logger::info('The number of currently running jobs exceed the limit');
|
||||
return;
|
||||
}
|
||||
|
||||
$outdated = DBA::count('gserver', ["`next_contact` < UTC_TIMESTAMP()"]);
|
||||
$total = DBA::count('gserver');
|
||||
Logger::info('Server status', ['total' => $total, 'outdated' => $outdated, 'updating' => $limit]);
|
||||
|
||||
$gservers = DBA::select('gserver', ['url'], ["`next_contact` < UTC_TIMESTAMP()"], ['limit' => $limit]);
|
||||
if (!DBA::isResult($gservers)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$updated = 0;
|
||||
|
||||
$count = 0;
|
||||
while ($gserver = DBA::fetch($gservers)) {
|
||||
if (!GServer::updateNeeded($gserver['created'], '', $gserver['last_failure'], $gserver['last_contact'])) {
|
||||
continue;
|
||||
}
|
||||
Logger::info('Update server status', ['server' => $gserver['url']]);
|
||||
|
||||
Worker::add(PRIORITY_LOW, 'UpdateGServer', $gserver['url']);
|
||||
|
||||
if (++$updated > 250) {
|
||||
return;
|
||||
}
|
||||
Worker::add(PRIORITY_LOW, 'UpdateGServer', $gserver['url'], false, true);
|
||||
$count++;
|
||||
}
|
||||
DBA::close($gservers);
|
||||
Logger::info('Updated servers', ['count' => $count]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,16 +39,27 @@ class UpdatePublicContacts
|
|||
$ids = [];
|
||||
$base_condition = ['network' => Protocol::FEDERATED, 'uid' => 0, 'self' => false];
|
||||
|
||||
$existing = Worker::countWorkersByCommand('UpdateContact');
|
||||
Logger::info('Already existing jobs', ['existing' => $existing]);
|
||||
if ($existing > 100) {
|
||||
return;
|
||||
}
|
||||
|
||||
$limit = 100 - $existing;
|
||||
|
||||
if (!DI::config()->get('system', 'update_active_contacts')) {
|
||||
$part = 3;
|
||||
// Add every contact (mostly failed ones) that hadn't been updated for six months
|
||||
$condition = DBA::mergeConditions($base_condition,
|
||||
["`last-update` < ?", DateTimeFormat::utc('now - 6 month')]);
|
||||
$ids = self::getContactsToUpdate($condition, $ids);
|
||||
$ids = self::getContactsToUpdate($condition, $ids, round($limit / $part));
|
||||
|
||||
// Add every non failed contact that hadn't been updated for a month
|
||||
$condition = DBA::mergeConditions($base_condition,
|
||||
["NOT `failed` AND `last-update` < ?", DateTimeFormat::utc('now - 1 month')]);
|
||||
$ids = self::getContactsToUpdate($condition, $ids);
|
||||
$ids = self::getContactsToUpdate($condition, $ids, round($limit / $part));
|
||||
} else {
|
||||
$part = 1;
|
||||
}
|
||||
|
||||
// Add every contact our system interacted with and hadn't been updated for a week
|
||||
|
@ -56,7 +67,7 @@ class UpdatePublicContacts
|
|||
`id` IN (SELECT `owner-id` FROM `item`) OR `id` IN (SELECT `causer-id` FROM `item`) OR
|
||||
`id` IN (SELECT `cid` FROM `post-tag`) OR `id` IN (SELECT `cid` FROM `user-contact`)) AND
|
||||
`last-update` < ?", DateTimeFormat::utc('now - 1 week')]);
|
||||
$ids = self::getContactsToUpdate($condition, $ids);
|
||||
$ids = self::getContactsToUpdate($condition, $ids, round($limit / $part));
|
||||
|
||||
foreach ($ids as $id) {
|
||||
Worker::add(PRIORITY_LOW, "UpdateContact", $id);
|
||||
|
@ -73,9 +84,9 @@ class UpdatePublicContacts
|
|||
* @param array $ids
|
||||
* @return array contact ids
|
||||
*/
|
||||
private static function getContactsToUpdate(array $condition, array $ids = [])
|
||||
private static function getContactsToUpdate(array $condition, array $ids = [], int $limit)
|
||||
{
|
||||
$contacts = DBA::select('contact', ['id'], $condition, ['limit' => 100, 'order' => ['last-update']]);
|
||||
$contacts = DBA::select('contact', ['id'], $condition, ['limit' => $limit, 'order' => ['last-update']]);
|
||||
while ($contact = DBA::fetch($contacts)) {
|
||||
$ids[] = $contact['id'];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue