Replace App with AppHelper in Worker classes

This commit is contained in:
Art4 2024-11-08 07:42:35 +00:00
parent 1d5fc6a4bf
commit 60a9833130
6 changed files with 23 additions and 23 deletions

View file

@ -533,7 +533,7 @@ class Worker
*/ */
private static function execFunction(array $queue, string $funcname, array $argv, bool $method_call) private static function execFunction(array $queue, string $funcname, array $argv, bool $method_call)
{ {
$a = DI::app(); $appHelper = DI::apphelper();
self::coolDown(); self::coolDown();
@ -547,7 +547,7 @@ class Worker
// For this reason the variables have to be initialized. // For this reason the variables have to be initialized.
DI::profiler()->reset(); DI::profiler()->reset();
$a->setQueue($queue); $appHelper->setQueue($queue);
$up_duration = microtime(true) - self::$up_start; $up_duration = microtime(true) - self::$up_start;
@ -571,7 +571,7 @@ class Worker
Logger::disableWorker(); Logger::disableWorker();
$a->setQueue([]); $appHelper->setQueue([]);
$duration = (microtime(true) - $stamp); $duration = (microtime(true) - $stamp);
@ -830,7 +830,7 @@ class Worker
return false; return false;
} elseif ($max_idletime > 0) { } elseif ($max_idletime > 0) {
Logger::debug('Maximum idletime not reached.', ['last' => $last_check, 'last-check' => $last_date, 'seconds' => $max_idletime, 'load' => $load, 'max_load' => $maxsysload, 'active_worker' => $active, 'max_worker' => $maxqueues]); Logger::debug('Maximum idletime not reached.', ['last' => $last_check, 'last-check' => $last_date, 'seconds' => $max_idletime, 'load' => $load, 'max_load' => $maxsysload, 'active_worker' => $active, 'max_worker' => $maxqueues]);
} }
} }
} }
@ -1371,20 +1371,20 @@ class Worker
*/ */
public static function getRetrial(): int public static function getRetrial(): int
{ {
$queue = DI::app()->getQueue(); $queue = DI::apphelper()->getQueue();
return $queue['retrial'] ?? 0; return $queue['retrial'] ?? 0;
} }
/** /**
* Defers the current worker entry * Defers the current worker entry
* *
* @param int $worker_defer_limit Maximum defer limit * @param int $worker_defer_limit Maximum defer limit
* @return boolean had the entry been deferred? * @return boolean had the entry been deferred?
* @throws \Exception * @throws \Exception
*/ */
public static function defer(int $worker_defer_limit = 0): bool public static function defer(int $worker_defer_limit = 0): bool
{ {
$queue = DI::app()->getQueue(); $queue = DI::apphelper()->getQueue();
if (empty($queue)) { if (empty($queue)) {
return false; return false;

View file

@ -192,7 +192,7 @@ class Queue
} }
if (!empty($entry['wid'])) { if (!empty($entry['wid'])) {
$worker = DI::app()->getQueue(); $worker = DI::apphelper()->getQueue();
$wid = $worker['id'] ?? 0; $wid = $worker['id'] ?? 0;
if ($entry['wid'] != $wid) { if ($entry['wid'] != $wid) {
$workerqueue = DBA::selectFirst('workerqueue', ['pid'], ['id' => $entry['wid'], 'done' => false]); $workerqueue = DBA::selectFirst('workerqueue', ['pid'], ['id' => $entry['wid'], 'done' => false]);

View file

@ -21,7 +21,7 @@ class Expire
{ {
public static function execute($param = '', $hook_function = '') public static function execute($param = '', $hook_function = '')
{ {
$a = DI::app(); $appHelper = DI::apphelper();
Hook::loadHooks(); Hook::loadHooks();
@ -48,7 +48,7 @@ class Expire
$r = DBA::select('user', ['uid', 'username'], ["`expire` != ?", 0]); $r = DBA::select('user', ['uid', 'username'], ["`expire` != ?", 0]);
while ($row = DBA::fetch($r)) { while ($row = DBA::fetch($r)) {
Logger::info('Calling expiry', ['user' => $row['uid'], 'username' => $row['username']]); Logger::info('Calling expiry', ['user' => $row['uid'], 'username' => $row['username']]);
Worker::add(['priority' => $a->getQueueValue('priority'), 'created' => $a->getQueueValue('created'), 'dont_fork' => true], Worker::add(['priority' => $appHelper->getQueueValue('priority'), 'created' => $appHelper->getQueueValue('created'), 'dont_fork' => true],
'Expire', (int)$row['uid']); 'Expire', (int)$row['uid']);
} }
DBA::close($r); DBA::close($r);
@ -56,7 +56,7 @@ class Expire
Logger::notice('calling hooks'); Logger::notice('calling hooks');
foreach (Hook::getByName('expire') as $hook) { foreach (Hook::getByName('expire') as $hook) {
Logger::info('Calling expire', ['hook' => $hook[1]]); Logger::info('Calling expire', ['hook' => $hook[1]]);
Worker::add(['priority' => $a->getQueueValue('priority'), 'created' => $a->getQueueValue('created'), 'dont_fork' => true], Worker::add(['priority' => $appHelper->getQueueValue('priority'), 'created' => $appHelper->getQueueValue('created'), 'dont_fork' => true],
'Expire', 'hook', $hook[1]); 'Expire', 'hook', $hook[1]);
} }

View file

@ -40,7 +40,7 @@ class FetchMissingActivity
Logger::info('Defer limit reached, activity could not be fetched', ['url' => $url]); Logger::info('Defer limit reached, activity could not be fetched', ['url' => $url]);
// recursively delete all entries that belong to this worker task // recursively delete all entries that belong to this worker task
$queue = DI::app()->getQueue(); $queue = DI::apphelper()->getQueue();
if (!empty($queue['id'])) { if (!empty($queue['id'])) {
Queue::deleteByWorkerId($queue['id']); Queue::deleteByWorkerId($queue['id']);
} }

View file

@ -41,7 +41,7 @@ class Notifier
{ {
public static function execute(string $cmd, int $post_uriid, int $sender_uid = 0) public static function execute(string $cmd, int $post_uriid, int $sender_uid = 0)
{ {
$a = DI::app(); $appHelper = DI::apphelper();
Logger::info('Invoked', ['cmd' => $cmd, 'target' => $post_uriid, 'sender_uid' => $sender_uid]); Logger::info('Invoked', ['cmd' => $cmd, 'target' => $post_uriid, 'sender_uid' => $sender_uid]);
@ -69,7 +69,7 @@ class Notifier
foreach ($inboxes as $inbox => $receivers) { foreach ($inboxes as $inbox => $receivers) {
$ap_contacts = array_merge($ap_contacts, $receivers); $ap_contacts = array_merge($ap_contacts, $receivers);
Logger::info('Delivery via ActivityPub', ['cmd' => $cmd, 'target' => $target_id, 'inbox' => $inbox]); Logger::info('Delivery via ActivityPub', ['cmd' => $cmd, 'target' => $target_id, 'inbox' => $inbox]);
Worker::add(['priority' => Worker::PRIORITY_HIGH, 'created' => $a->getQueueValue('created'), 'dont_fork' => true], Worker::add(['priority' => Worker::PRIORITY_HIGH, 'created' => $appHelper->getQueueValue('created'), 'dont_fork' => true],
'APDelivery', $cmd, $target_id, $inbox, $uid, $receivers, $post_uriid); 'APDelivery', $cmd, $target_id, $inbox, $uid, $receivers, $post_uriid);
} }
} elseif ($cmd == Delivery::SUGGESTION) { } elseif ($cmd == Delivery::SUGGESTION) {
@ -77,7 +77,7 @@ class Notifier
$uid = $suggest->uid; $uid = $suggest->uid;
$recipients[] = $suggest->cid; $recipients[] = $suggest->cid;
} elseif ($cmd == Delivery::REMOVAL) { } elseif ($cmd == Delivery::REMOVAL) {
return self::notifySelfRemoval($target_id, $a->getQueueValue('priority'), $a->getQueueValue('created')); return self::notifySelfRemoval($target_id, $appHelper->getQueueValue('priority'), $appHelper->getQueueValue('created'));
} elseif ($cmd == Delivery::RELOCATION) { } elseif ($cmd == Delivery::RELOCATION) {
$uid = $target_id; $uid = $target_id;
@ -162,7 +162,7 @@ class Notifier
Logger::info('Got post', ['guid' => $target_item['guid'], 'uri-id' => $target_item['uri-id'], 'network' => $target_item['network'], 'parent-network' => $parent['network'], 'thread-parent-network' => $thr_parent['network']]); Logger::info('Got post', ['guid' => $target_item['guid'], 'uri-id' => $target_item['uri-id'], 'network' => $target_item['network'], 'parent-network' => $parent['network'], 'thread-parent-network' => $thr_parent['network']]);
if (!self::isRemovalActivity($cmd, $owner, Protocol::ACTIVITYPUB)) { if (!self::isRemovalActivity($cmd, $owner, Protocol::ACTIVITYPUB)) {
$apdelivery = self::activityPubDelivery($cmd, $target_item, $parent, $thr_parent, $a->getQueueValue('priority'), $a->getQueueValue('created'), $owner); $apdelivery = self::activityPubDelivery($cmd, $target_item, $parent, $thr_parent, $appHelper->getQueueValue('priority'), $appHelper->getQueueValue('created'), $owner);
$ap_contacts = $apdelivery['contacts']; $ap_contacts = $apdelivery['contacts'];
$delivery_queue_count += $apdelivery['count']; $delivery_queue_count += $apdelivery['count'];
// Restrict distribution to AP, when there are no permissions. // Restrict distribution to AP, when there are no permissions.
@ -386,7 +386,7 @@ class Notifier
if (!empty($target_item)) { if (!empty($target_item)) {
Logger::info('Calling hooks for ' . $cmd . ' ' . $target_id); Logger::info('Calling hooks for ' . $cmd . ' ' . $target_id);
Hook::fork($a->getQueueValue('priority'), 'notifier_normal', $target_item); Hook::fork($appHelper->getQueueValue('priority'), 'notifier_normal', $target_item);
Hook::callAll('notifier_end', $target_item); Hook::callAll('notifier_end', $target_item);
@ -424,7 +424,7 @@ class Notifier
*/ */
private static function delivery(string $cmd, int $post_uriid, int $sender_uid, array $target_item, array $thr_parent, array $owner, bool $batch_delivery, bool $in_batch, array $contacts, array $ap_contacts, array $conversants = []): int private static function delivery(string $cmd, int $post_uriid, int $sender_uid, array $target_item, array $thr_parent, array $owner, bool $batch_delivery, bool $in_batch, array $contacts, array $ap_contacts, array $conversants = []): int
{ {
$a = DI::app(); $appHelper = DI::apphelper();
$delivery_queue_count = 0; $delivery_queue_count = 0;
if (!empty($target_item['verb']) && ($target_item['verb'] == Activity::ANNOUNCE)) { if (!empty($target_item['verb']) && ($target_item['verb'] == Activity::ANNOUNCE)) {
@ -511,10 +511,10 @@ class Notifier
// Situation is that sometimes Friendica servers receive Friendica posts over the Diaspora protocol first. // Situation is that sometimes Friendica servers receive Friendica posts over the Diaspora protocol first.
// The conversion in Markdown reduces the formatting, so these posts should arrive after the Friendica posts. // The conversion in Markdown reduces the formatting, so these posts should arrive after the Friendica posts.
// This is only important for high and medium priority tasks and not for Low priority jobs like deletions. // This is only important for high and medium priority tasks and not for Low priority jobs like deletions.
if (($contact['network'] == Protocol::DIASPORA) && in_array($a->getQueueValue('priority'), [Worker::PRIORITY_HIGH, Worker::PRIORITY_MEDIUM])) { if (($contact['network'] == Protocol::DIASPORA) && in_array($appHelper->getQueueValue('priority'), [Worker::PRIORITY_HIGH, Worker::PRIORITY_MEDIUM])) {
$deliver_options = ['priority' => $a->getQueueValue('priority'), 'dont_fork' => true]; $deliver_options = ['priority' => $appHelper->getQueueValue('priority'), 'dont_fork' => true];
} else { } else {
$deliver_options = ['priority' => $a->getQueueValue('priority'), 'created' => $a->getQueueValue('created'), 'dont_fork' => true]; $deliver_options = ['priority' => $appHelper->getQueueValue('priority'), 'created' => $appHelper->getQueueValue('created'), 'dont_fork' => true];
} }
if (!empty($contact['gsid']) && DI::config()->get('system', 'bulk_delivery')) { if (!empty($contact['gsid']) && DI::config()->get('system', 'bulk_delivery')) {

View file

@ -30,13 +30,13 @@ class ProfileUpdate {
return; return;
} }
$a = DI::app(); $appHelper = DI::apphelper();
$inboxes = ActivityPub\Transmitter::fetchTargetInboxesforUser($uid); $inboxes = ActivityPub\Transmitter::fetchTargetInboxesforUser($uid);
foreach ($inboxes as $inbox => $receivers) { foreach ($inboxes as $inbox => $receivers) {
Logger::info('Profile update for user ' . $uid . ' to ' . $inbox .' via ActivityPub'); Logger::info('Profile update for user ' . $uid . ' to ' . $inbox .' via ActivityPub');
Worker::add(['priority' => $a->getQueueValue('priority'), 'created' => $a->getQueueValue('created'), 'dont_fork' => true], Worker::add(['priority' => $appHelper->getQueueValue('priority'), 'created' => $appHelper->getQueueValue('created'), 'dont_fork' => true],
'APDelivery', 'APDelivery',
Delivery::PROFILEUPDATE, Delivery::PROFILEUPDATE,
0, 0,