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)
{
$a = DI::app();
$appHelper = DI::apphelper();
self::coolDown();
@ -547,7 +547,7 @@ class Worker
// For this reason the variables have to be initialized.
DI::profiler()->reset();
$a->setQueue($queue);
$appHelper->setQueue($queue);
$up_duration = microtime(true) - self::$up_start;
@ -571,7 +571,7 @@ class Worker
Logger::disableWorker();
$a->setQueue([]);
$appHelper->setQueue([]);
$duration = (microtime(true) - $stamp);
@ -830,7 +830,7 @@ class Worker
return false;
} 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]);
}
}
}
}
@ -1371,20 +1371,20 @@ class Worker
*/
public static function getRetrial(): int
{
$queue = DI::app()->getQueue();
$queue = DI::apphelper()->getQueue();
return $queue['retrial'] ?? 0;
}
/**
* 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?
* @throws \Exception
*/
public static function defer(int $worker_defer_limit = 0): bool
{
$queue = DI::app()->getQueue();
$queue = DI::apphelper()->getQueue();
if (empty($queue)) {
return false;

View file

@ -192,7 +192,7 @@ class Queue
}
if (!empty($entry['wid'])) {
$worker = DI::app()->getQueue();
$worker = DI::apphelper()->getQueue();
$wid = $worker['id'] ?? 0;
if ($entry['wid'] != $wid) {
$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 = '')
{
$a = DI::app();
$appHelper = DI::apphelper();
Hook::loadHooks();
@ -48,7 +48,7 @@ class Expire
$r = DBA::select('user', ['uid', 'username'], ["`expire` != ?", 0]);
while ($row = DBA::fetch($r)) {
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']);
}
DBA::close($r);
@ -56,7 +56,7 @@ class Expire
Logger::notice('calling hooks');
foreach (Hook::getByName('expire') as $hook) {
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]);
}

View file

@ -40,7 +40,7 @@ class FetchMissingActivity
Logger::info('Defer limit reached, activity could not be fetched', ['url' => $url]);
// recursively delete all entries that belong to this worker task
$queue = DI::app()->getQueue();
$queue = DI::apphelper()->getQueue();
if (!empty($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)
{
$a = DI::app();
$appHelper = DI::apphelper();
Logger::info('Invoked', ['cmd' => $cmd, 'target' => $post_uriid, 'sender_uid' => $sender_uid]);
@ -69,7 +69,7 @@ class Notifier
foreach ($inboxes as $inbox => $receivers) {
$ap_contacts = array_merge($ap_contacts, $receivers);
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);
}
} elseif ($cmd == Delivery::SUGGESTION) {
@ -77,7 +77,7 @@ class Notifier
$uid = $suggest->uid;
$recipients[] = $suggest->cid;
} 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) {
$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']]);
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'];
$delivery_queue_count += $apdelivery['count'];
// Restrict distribution to AP, when there are no permissions.
@ -386,7 +386,7 @@ class Notifier
if (!empty($target_item)) {
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);
@ -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
{
$a = DI::app();
$appHelper = DI::apphelper();
$delivery_queue_count = 0;
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.
// 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.
if (($contact['network'] == Protocol::DIASPORA) && in_array($a->getQueueValue('priority'), [Worker::PRIORITY_HIGH, Worker::PRIORITY_MEDIUM])) {
$deliver_options = ['priority' => $a->getQueueValue('priority'), 'dont_fork' => true];
if (($contact['network'] == Protocol::DIASPORA) && in_array($appHelper->getQueueValue('priority'), [Worker::PRIORITY_HIGH, Worker::PRIORITY_MEDIUM])) {
$deliver_options = ['priority' => $appHelper->getQueueValue('priority'), 'dont_fork' => true];
} 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')) {

View file

@ -30,13 +30,13 @@ class ProfileUpdate {
return;
}
$a = DI::app();
$appHelper = DI::apphelper();
$inboxes = ActivityPub\Transmitter::fetchTargetInboxesforUser($uid);
foreach ($inboxes as $inbox => $receivers) {
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',
Delivery::PROFILEUPDATE,
0,