mirror of
https://github.com/friendica/friendica
synced 2025-01-30 23:39:47 +00:00
Replace Logger with DI::logger() in Update Worker classes
This commit is contained in:
parent
0ce0aa4d2c
commit
c2f65af8bf
8 changed files with 35 additions and 42 deletions
|
@ -7,7 +7,6 @@
|
|||
|
||||
namespace Friendica\Worker;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\GServer;
|
||||
|
@ -20,7 +19,7 @@ class UpdateBlockedServers
|
|||
*/
|
||||
public static function execute()
|
||||
{
|
||||
Logger::info('Update blocked servers - start');
|
||||
DI::logger()->info('Update blocked servers - start');
|
||||
$gservers = DBA::select('gserver', ['id', 'url', 'blocked']);
|
||||
$changed = 0;
|
||||
$unchanged = 0;
|
||||
|
@ -39,12 +38,12 @@ class UpdateBlockedServers
|
|||
$changed++;
|
||||
}
|
||||
DBA::close($gservers);
|
||||
Logger::info('Update blocked servers - done', ['changed' => $changed, 'unchanged' => $unchanged]);
|
||||
DI::logger()->info('Update blocked servers - done', ['changed' => $changed, 'unchanged' => $unchanged]);
|
||||
|
||||
if (DI::config()->get('system', 'delete-blocked-servers')) {
|
||||
Logger::info('Delete blocked servers - start');
|
||||
DI::logger()->info('Delete blocked servers - start');
|
||||
$ret = DBA::delete('gserver', ["`blocked` AND NOT EXISTS(SELECT `gsid` FROM `inbox-status` WHERE `gsid` = `gserver`.`id`) AND NOT EXISTS(SELECT `gsid` FROM `contact` WHERE gsid= `gserver`.`id`) AND NOT EXISTS(SELECT `gsid` FROM `apcontact` WHERE `gsid` = `gserver`.`id`) AND NOT EXISTS(SELECT `gsid` FROM `delivery-queue` WHERE `gsid` = `gserver`.`id`) AND NOT EXISTS(SELECT `gsid` FROM `diaspora-contact` WHERE `gsid` = `gserver`.`id`) AND NOT EXISTS(SELECT `gserver-id` FROM `gserver-tag` WHERE `gserver-id` = `gserver`.`id`)"]);
|
||||
Logger::info('Delete blocked servers - done', ['ret' => $ret, 'rows' => DBA::affectedRows()]);
|
||||
DI::logger()->info('Delete blocked servers - done', ['ret' => $ret, 'rows' => DBA::affectedRows()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
namespace Friendica\Worker;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
|
||||
|
@ -31,7 +31,7 @@ class UpdateContact
|
|||
|
||||
$success = Contact::updateFromProbe($contact_id);
|
||||
|
||||
Logger::info('Updated from probe', ['id' => $contact_id, 'success' => $success]);
|
||||
DI::logger()->info('Updated from probe', ['id' => $contact_id, 'success' => $success]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
namespace Friendica\Worker;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
|
@ -30,11 +29,11 @@ class UpdateContacts
|
|||
$updating = Worker::countWorkersByCommand('UpdateContact');
|
||||
$limit = $update_limit - $updating;
|
||||
if ($limit <= 0) {
|
||||
Logger::info('The number of currently running jobs exceed the limit');
|
||||
DI::logger()->info('The number of currently running jobs exceed the limit');
|
||||
return;
|
||||
}
|
||||
|
||||
Logger::info('Updating contact', ['count' => $limit]);
|
||||
DI::logger()->info('Updating contact', ['count' => $limit]);
|
||||
|
||||
$condition = ['self' => false];
|
||||
|
||||
|
@ -54,20 +53,20 @@ class UpdateContacts
|
|||
if ((!empty($contact['gsid']) || !empty($contact['baseurl'])) && GServer::reachable($contact)) {
|
||||
$stamp = (float)microtime(true);
|
||||
$success = Contact::updateFromProbe($contact['id']);
|
||||
Logger::debug('Direct update', ['id' => $contact['id'], 'count' => $count, 'duration' => round((float)microtime(true) - $stamp, 3), 'success' => $success]);
|
||||
DI::logger()->debug('Direct update', ['id' => $contact['id'], 'count' => $count, 'duration' => round((float)microtime(true) - $stamp, 3), 'success' => $success]);
|
||||
++$count;
|
||||
} elseif (UpdateContact::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], $contact['id'])) {
|
||||
Logger::debug('Update by worker', ['id' => $contact['id'], 'count' => $count]);
|
||||
DI::logger()->debug('Update by worker', ['id' => $contact['id'], 'count' => $count]);
|
||||
++$count;
|
||||
}
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
Logger::notice($e->getMessage(), ['contact' => $contact]);
|
||||
DI::logger()->notice($e->getMessage(), ['contact' => $contact]);
|
||||
}
|
||||
|
||||
Worker::coolDown();
|
||||
}
|
||||
DBA::close($contacts);
|
||||
|
||||
Logger::info('Initiated update for federated contacts', ['count' => $count]);
|
||||
DI::logger()->info('Initiated update for federated contacts', ['count' => $count]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,15 +7,13 @@
|
|||
|
||||
namespace Friendica\Worker;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\GServer;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Friendica\Util\Network;
|
||||
use Friendica\Util\Strings;
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
|
||||
class UpdateGServer
|
||||
{
|
||||
|
@ -62,7 +60,7 @@ class UpdateGServer
|
|||
}
|
||||
|
||||
$ret = GServer::check($filtered, '', true, $only_nodeinfo);
|
||||
Logger::info('Updated gserver', ['url' => $filtered, 'result' => $ret]);
|
||||
DI::logger()->info('Updated gserver', ['url' => $filtered, 'result' => $ret]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
namespace Friendica\Worker;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
|
@ -31,14 +30,14 @@ class UpdateGServers
|
|||
$updating = Worker::countWorkersByCommand('UpdateGServer');
|
||||
$limit = $update_limit - $updating;
|
||||
if ($limit <= 0) {
|
||||
Logger::info('The number of currently running jobs exceed the limit');
|
||||
DI::logger()->info('The number of currently running jobs exceed the limit');
|
||||
return;
|
||||
}
|
||||
|
||||
$total = DBA::count('gserver');
|
||||
$condition = ["NOT `blocked` AND `next_contact` < ? AND (`nurl` != ? OR `url` != ?)", DateTimeFormat::utcNow(), '', ''];
|
||||
$outdated = DBA::count('gserver', $condition);
|
||||
Logger::info('Server status', ['total' => $total, 'outdated' => $outdated, 'updating' => $limit]);
|
||||
DI::logger()->info('Server status', ['total' => $total, 'outdated' => $outdated, 'updating' => $limit]);
|
||||
|
||||
$gservers = DBA::select('gserver', ['id', 'url', 'nurl', 'failed', 'created', 'last_contact'], $condition, ['limit' => $limit]);
|
||||
if (!DBA::isResult($gservers)) {
|
||||
|
@ -49,7 +48,7 @@ class UpdateGServers
|
|||
while ($gserver = DBA::fetch($gservers)) {
|
||||
if (DI::config()->get('system', 'update_active_contacts') && !Contact::exists(['gsid' => $gserver['id'], 'local-data' => true])) {
|
||||
$next_update = GServer::getNextUpdateDate(!$gserver['failed'], $gserver['created'], $gserver['last_contact']);
|
||||
Logger::debug('Skip server without contacts with local data', ['url' => $gserver['url'], 'failed' => $gserver['failed'], 'next_update' => $next_update]);
|
||||
DI::logger()->debug('Skip server without contacts with local data', ['url' => $gserver['url'], 'failed' => $gserver['failed'], 'next_update' => $next_update]);
|
||||
GServer::update(['next_contact' => $next_update], ['nurl' => $gserver['nurl']]);
|
||||
continue;
|
||||
}
|
||||
|
@ -70,6 +69,6 @@ class UpdateGServers
|
|||
Worker::coolDown();
|
||||
}
|
||||
DBA::close($gservers);
|
||||
Logger::info('Updated servers', ['count' => $count]);
|
||||
DI::logger()->info('Updated servers', ['count' => $count]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,19 +7,19 @@
|
|||
|
||||
namespace Friendica\Worker;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact\Relation;
|
||||
use Friendica\Model\Post;
|
||||
|
||||
/**
|
||||
* Update the interaction scores
|
||||
* Update the interaction scores
|
||||
*/
|
||||
class UpdateScores
|
||||
{
|
||||
public static function execute($param = '', $hook_function = '')
|
||||
{
|
||||
Logger::notice('Start score update');
|
||||
DI::logger()->notice('Start score update');
|
||||
|
||||
$users = DBA::select('user', ['uid'], ["`verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired` AND `uid` > ?", 0]);
|
||||
while ($user = DBA::fetch($users)) {
|
||||
|
@ -27,7 +27,7 @@ class UpdateScores
|
|||
}
|
||||
DBA::close($users);
|
||||
|
||||
Logger::notice('Score update done');
|
||||
DI::logger()->notice('Score update done');
|
||||
|
||||
Post\Engagement::expire();
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
namespace Friendica\Worker;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\GServer;
|
||||
|
@ -38,17 +37,17 @@ class UpdateServerDirectory
|
|||
{
|
||||
$result = DI::httpClient()->fetch($gserver['poco'] . '?fields=urls', HttpClientAccept::JSON, 0, '', HttpClientRequest::SERVERDISCOVER);
|
||||
if (empty($result)) {
|
||||
Logger::info('Empty result', ['url' => $gserver['url']]);
|
||||
DI::logger()->info('Empty result', ['url' => $gserver['url']]);
|
||||
return;
|
||||
}
|
||||
|
||||
$contacts = json_decode($result, true);
|
||||
if (empty($contacts['entry'])) {
|
||||
Logger::info('No contacts', ['url' => $gserver['url']]);
|
||||
DI::logger()->info('No contacts', ['url' => $gserver['url']]);
|
||||
return;
|
||||
}
|
||||
|
||||
Logger::info('PoCo discovery started', ['poco' => $gserver['poco']]);
|
||||
DI::logger()->info('PoCo discovery started', ['poco' => $gserver['poco']]);
|
||||
|
||||
$urls = [];
|
||||
foreach (array_column($contacts['entry'], 'urls') as $url_entries) {
|
||||
|
@ -64,24 +63,24 @@ class UpdateServerDirectory
|
|||
|
||||
$result = Contact::addByUrls($urls);
|
||||
|
||||
Logger::info('PoCo discovery ended', ['count' => $result['count'], 'added' => $result['added'], 'updated' => $result['updated'], 'unchanged' => $result['unchanged'], 'poco' => $gserver['poco']]);
|
||||
DI::logger()->info('PoCo discovery ended', ['count' => $result['count'], 'added' => $result['added'], 'updated' => $result['updated'], 'unchanged' => $result['unchanged'], 'poco' => $gserver['poco']]);
|
||||
}
|
||||
|
||||
private static function discoverMastodonDirectory(array $gserver)
|
||||
{
|
||||
$result = DI::httpClient()->fetch($gserver['url'] . '/api/v1/directory?order=new&local=true&limit=200&offset=0', HttpClientAccept::JSON, 0, '', HttpClientRequest::SERVERDISCOVER);
|
||||
if (empty($result)) {
|
||||
Logger::info('Empty result', ['url' => $gserver['url']]);
|
||||
DI::logger()->info('Empty result', ['url' => $gserver['url']]);
|
||||
return;
|
||||
}
|
||||
|
||||
$accounts = json_decode($result, true);
|
||||
if (!is_array($accounts)) {
|
||||
Logger::info('No contacts', ['url' => $gserver['url']]);
|
||||
DI::logger()->info('No contacts', ['url' => $gserver['url']]);
|
||||
return;
|
||||
}
|
||||
|
||||
Logger::info('Account discovery started', ['url' => $gserver['url']]);
|
||||
DI::logger()->info('Account discovery started', ['url' => $gserver['url']]);
|
||||
|
||||
$urls = [];
|
||||
foreach ($accounts as $account) {
|
||||
|
@ -92,6 +91,6 @@ class UpdateServerDirectory
|
|||
|
||||
$result = Contact::addByUrls($urls);
|
||||
|
||||
Logger::info('Account discovery ended', ['count' => $result['count'], 'added' => $result['added'], 'updated' => $result['updated'], 'unchanged' => $result['unchanged'], 'url' => $gserver['url']]);
|
||||
DI::logger()->info('Account discovery ended', ['count' => $result['count'], 'added' => $result['added'], 'updated' => $result['updated'], 'unchanged' => $result['unchanged'], 'url' => $gserver['url']]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
namespace Friendica\Worker;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
|
@ -35,21 +34,21 @@ class UpdateServerPeers
|
|||
try {
|
||||
$ret = DI::httpClient()->get($url . '/api/v1/instance/peers', HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERDISCOVER]);
|
||||
} catch (\Throwable $th) {
|
||||
Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
|
||||
DI::logger()->notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
|
||||
return;
|
||||
}
|
||||
if (!$ret->isSuccess() || empty($ret->getBodyString())) {
|
||||
Logger::info('Server is not reachable or does not offer the "peers" endpoint', ['url' => $url]);
|
||||
DI::logger()->info('Server is not reachable or does not offer the "peers" endpoint', ['url' => $url]);
|
||||
return;
|
||||
}
|
||||
|
||||
$peers = json_decode($ret->getBodyString());
|
||||
if (empty($peers) || !is_array($peers)) {
|
||||
Logger::info('Server does not have any peers listed', ['url' => $url]);
|
||||
DI::logger()->info('Server does not have any peers listed', ['url' => $url]);
|
||||
return;
|
||||
}
|
||||
|
||||
Logger::info('Server peer update start', ['url' => $url]);
|
||||
DI::logger()->info('Server peer update start', ['url' => $url]);
|
||||
|
||||
$total = 0;
|
||||
$added = 0;
|
||||
|
@ -69,6 +68,6 @@ class UpdateServerPeers
|
|||
++$added;
|
||||
Worker::coolDown();
|
||||
}
|
||||
Logger::info('Server peer update ended', ['total' => $total, 'added' => $added, 'url' => $url]);
|
||||
DI::logger()->info('Server peer update ended', ['total' => $total, 'added' => $added, 'url' => $url]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue