From 018858934b0423efb7dd07e660f621f1e8eb75cd Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 17 Oct 2022 05:49:55 +0000 Subject: [PATCH] The priority is now a class constant --- boot.php | 15 ------- mod/events.php | 2 +- mod/item.php | 3 +- mod/tagger.php | 2 +- src/Console/Relocate.php | 2 +- src/Core/Search.php | 2 +- src/Core/Update.php | 2 +- src/Core/UserImport.php | 2 +- src/Core/Worker.php | 50 +++++++++++++--------- src/Core/Worker/Cron.php | 24 +++++------ src/Model/Contact.php | 32 +++++++------- src/Model/FContact.php | 2 +- src/Model/GServer.php | 6 +-- src/Model/Item.php | 12 +++--- src/Model/Mail.php | 2 +- src/Model/Post/Delayed.php | 2 +- src/Model/Profile.php | 4 +- src/Model/PushSubscriber.php | 6 +-- src/Model/Subscription.php | 2 +- src/Model/User.php | 8 ++-- src/Module/Admin/Blocklist/Contact.php | 2 +- src/Module/Admin/Blocklist/Server/Add.php | 2 +- src/Module/Admin/Site.php | 4 +- src/Module/Api/Friendica/Events/Create.php | 2 +- src/Module/Api/Mastodon/Statuses.php | 3 +- src/Module/Contact.php | 4 +- src/Module/FriendSuggest.php | 2 +- src/Module/Photo.php | 2 +- src/Module/Register.php | 2 +- src/Module/Settings/Account.php | 4 +- src/Protocol/ActivityPub/Processor.php | 6 +-- src/Protocol/ActivityPub/Receiver.php | 2 +- src/Protocol/Diaspora.php | 2 +- src/Protocol/Feed.php | 3 +- src/Worker/CheckDeletedContacts.php | 2 +- src/Worker/Cron.php | 38 ++++++++-------- src/Worker/Directory.php | 2 +- src/Worker/ExpirePosts.php | 4 +- src/Worker/MoveStorage.php | 2 +- src/Worker/Notifier.php | 10 ++--- src/Worker/PollContacts.php | 6 +-- src/Worker/RemoveUser.php | 3 +- src/Worker/UpdateContacts.php | 2 +- src/Worker/UpdateGServers.php | 4 +- static/defaults.config.php | 2 +- update.php | 4 +- 46 files changed, 148 insertions(+), 151 deletions(-) diff --git a/boot.php b/boot.php index 8e7958de3..b90c1fb2e 100644 --- a/boot.php +++ b/boot.php @@ -71,21 +71,6 @@ define('GRAVITY_COMMENT', 6); define('GRAVITY_UNKNOWN', 9); /* @}*/ -/** - * @name Priority - * - * Process priority for the worker - * @{ - */ -define('PRIORITY_UNDEFINED', 0); -define('PRIORITY_CRITICAL', 10); -define('PRIORITY_HIGH', 20); -define('PRIORITY_MEDIUM', 30); -define('PRIORITY_LOW', 40); -define('PRIORITY_NEGLIGIBLE', 50); -define('PRIORITIES', [PRIORITY_CRITICAL, PRIORITY_HIGH, PRIORITY_MEDIUM, PRIORITY_LOW, PRIORITY_NEGLIGIBLE]); -/* @}*/ - // Normally this constant is defined - but not if "pcntl" isn't installed if (!defined('SIGTERM')) { define('SIGTERM', 15); diff --git a/mod/events.php b/mod/events.php index 082cdf55d..eead66c01 100644 --- a/mod/events.php +++ b/mod/events.php @@ -205,7 +205,7 @@ function events_post(App $a) } if (!$cid && $uri_id) { - Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, (int)$uri_id, (int)$uid); + Worker::add(Worker::PRIORITY_HIGH, "Notifier", Delivery::POST, (int)$uri_id, (int)$uid); } DI::baseUrl()->redirect('events'); diff --git a/mod/item.php b/mod/item.php index f3f0fd40d..8f4494ca7 100644 --- a/mod/item.php +++ b/mod/item.php @@ -36,6 +36,7 @@ use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\Session; use Friendica\Core\System; +use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Attach; @@ -635,7 +636,7 @@ function item_post(App $a) { unset($datarray['self']); unset($datarray['api_source']); - Post\Delayed::add($datarray['uri'], $datarray, PRIORITY_HIGH, Post\Delayed::PREPARED_NO_HOOK, $scheduled_at); + Post\Delayed::add($datarray['uri'], $datarray, Worker::PRIORITY_HIGH, Post\Delayed::PREPARED_NO_HOOK, $scheduled_at); item_post_return(DI::baseUrl(), $api_source, $return_path); } } diff --git a/mod/tagger.php b/mod/tagger.php index e0d95ce66..45b743166 100644 --- a/mod/tagger.php +++ b/mod/tagger.php @@ -166,6 +166,6 @@ EOT; $post = Post::selectFirst(['uri-id', 'uid'], ['id' => $post_id]); - Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $post['uri-id'], $post['uid']); + Worker::add(Worker::PRIORITY_HIGH, "Notifier", Delivery::POST, $post['uri-id'], $post['uid']); System::exit(); } diff --git a/src/Console/Relocate.php b/src/Console/Relocate.php index c1db6ef53..729bee392 100644 --- a/src/Console/Relocate.php +++ b/src/Console/Relocate.php @@ -197,7 +197,7 @@ HELP; $this->out('Schedule relocation messages to remote Friendica and Diaspora hosts'); $users = $this->database->selectToArray('user', ['uid'], ['account_removed' => false, 'account_expired' => false]); foreach ($users as $user) { - Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::RELOCATION, $user['uid']); + Worker::add(Worker::PRIORITY_HIGH, 'Notifier', Delivery::RELOCATION, $user['uid']); } return 0; diff --git a/src/Core/Search.php b/src/Core/Search.php index 5ae1dd7ac..cf3821afc 100644 --- a/src/Core/Search.php +++ b/src/Core/Search.php @@ -192,7 +192,7 @@ class Search } // Add found profiles from the global directory to the local directory - Worker::add(PRIORITY_LOW, 'SearchDirectory', $search); + Worker::add(Worker::PRIORITY_LOW, 'SearchDirectory', $search); return $resultList; } diff --git a/src/Core/Update.php b/src/Core/Update.php index ddb9effd7..ad5b31760 100644 --- a/src/Core/Update.php +++ b/src/Core/Update.php @@ -92,7 +92,7 @@ class Update */ self::run($basePath); } else { - Worker::add(PRIORITY_CRITICAL, 'DBUpdate'); + Worker::add(Worker::PRIORITY_CRITICAL, 'DBUpdate'); } } } diff --git a/src/Core/UserImport.php b/src/Core/UserImport.php index 339ce0b65..f8485fc29 100644 --- a/src/Core/UserImport.php +++ b/src/Core/UserImport.php @@ -322,7 +322,7 @@ class UserImport } // send relocate messages - Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::RELOCATION, $newuid); + Worker::add(Worker::PRIORITY_HIGH, 'Notifier', Delivery::RELOCATION, $newuid); info(DI::l10n()->t("Done. You can now login with your username and password")); DI::baseUrl()->redirect('login'); diff --git a/src/Core/Worker.php b/src/Core/Worker.php index a57792ce7..9ec2f8f04 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -31,12 +31,20 @@ use Friendica\Util\DateTimeFormat; */ class Worker { - const PRIORITY_UNDEFINED = PRIORITY_UNDEFINED; - const PRIORITY_CRITICAL = PRIORITY_CRITICAL; - const PRIORITY_HIGH = PRIORITY_HIGH; - const PRIORITY_MEDIUM = PRIORITY_MEDIUM; - const PRIORITY_LOW = PRIORITY_LOW; - const PRIORITY_NEGLIGIBLE = PRIORITY_NEGLIGIBLE; + /** + * @name Priority + * + * Process priority for the worker + * @{ + */ + const PRIORITY_UNDEFINED = 0; + const PRIORITY_CRITICAL = 10; + const PRIORITY_HIGH = 20; + const PRIORITY_MEDIUM = 30; + const PRIORITY_LOW = 40; + const PRIORITY_NEGLIGIBLE = 50; + const PRIORITIES = [self::PRIORITY_CRITICAL, self::PRIORITY_HIGH, self::PRIORITY_MEDIUM, self::PRIORITY_LOW, self::PRIORITY_NEGLIGIBLE]; + /* @}*/ const STATE_STARTUP = 1; // Worker is in startup. This takes most time. const STATE_LONG_LOOP = 2; // Worker is processing the whole - long - loop. @@ -807,7 +815,7 @@ class Worker $top_priority = self::highestPriority(); $high_running = self::processWithPriorityActive($top_priority); - if (!$high_running && ($top_priority > PRIORITY_UNDEFINED) && ($top_priority < PRIORITY_NEGLIGIBLE)) { + if (!$high_running && ($top_priority > self::PRIORITY_UNDEFINED) && ($top_priority < self::PRIORITY_NEGLIGIBLE)) { Logger::info('Jobs with a higher priority are waiting but none is executed. Open a fastlane.', ['priority' => $top_priority]); $queues = $active + 1; } @@ -939,7 +947,7 @@ class Worker private static function nextPriority() { $waiting = []; - $priorities = [PRIORITY_CRITICAL, PRIORITY_HIGH, PRIORITY_MEDIUM, PRIORITY_LOW, PRIORITY_NEGLIGIBLE]; + $priorities = [self::PRIORITY_CRITICAL, self::PRIORITY_HIGH, self::PRIORITY_MEDIUM, self::PRIORITY_LOW, self::PRIORITY_NEGLIGIBLE]; foreach ($priorities as $priority) { $stamp = (float)microtime(true); if (DBA::exists('workerqueue', ["`priority` = ? AND `pid` = 0 AND NOT `done` AND `next_try` < ?", $priority, DateTimeFormat::utcNow()])) { @@ -948,8 +956,8 @@ class Worker self::$db_duration += (microtime(true) - $stamp); } - if (!empty($waiting[PRIORITY_CRITICAL])) { - return PRIORITY_CRITICAL; + if (!empty($waiting[self::PRIORITY_CRITICAL])) { + return self::PRIORITY_CRITICAL; } $running = []; @@ -1206,8 +1214,8 @@ class Worker * @param (integer|array) priority or parameter array, strings are deprecated and are ignored * * next args are passed as $cmd command line - * or: Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::DELETION, $drop_id); - * or: Worker::add(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), 'Delivery', $post_id); + * or: Worker::add(Worker::PRIORITY_HIGH, 'Notifier', Delivery::DELETION, $drop_id); + * or: Worker::add(array('priority' => Worker::PRIORITY_HIGH, 'dont_fork' => true), 'Delivery', $post_id); * * @return int '0' if worker queue entry already existed or there had been an error, otherwise the ID of the worker task * @throws \Friendica\Network\HTTPException\InternalServerErrorException @@ -1230,7 +1238,7 @@ class Worker return 1; } - $priority = PRIORITY_MEDIUM; + $priority = self::PRIORITY_MEDIUM; // Don't fork from frontend tasks by default $dont_fork = DI::config()->get('system', 'worker_dont_fork', false) || !DI::mode()->isBackend(); $created = DateTimeFormat::utcNow(); @@ -1266,9 +1274,9 @@ class Worker $found = DBA::exists('workerqueue', ['command' => $command, 'parameter' => $parameters, 'done' => false]); $added = 0; - if (!is_int($priority) || !in_array($priority, PRIORITIES)) { + if (!is_int($priority) || !in_array($priority, self::PRIORITIES)) { Logger::warning('Invalid priority', ['priority' => $priority, 'command' => $command, 'callstack' => System::callstack(20)]); - $priority = PRIORITY_MEDIUM; + $priority = self::PRIORITY_MEDIUM; } // Quit if there was a database error - a precaution for the update process to 3.5.3 @@ -1383,12 +1391,12 @@ class Worker $delay = (($new_retrial + 2) ** 4) + (rand(1, 30) * ($new_retrial)); $next = DateTimeFormat::utc('now + ' . $delay . ' seconds'); - if (($priority < PRIORITY_MEDIUM) && ($new_retrial > 3)) { - $priority = PRIORITY_MEDIUM; - } elseif (($priority < PRIORITY_LOW) && ($new_retrial > 6)) { - $priority = PRIORITY_LOW; - } elseif (($priority < PRIORITY_NEGLIGIBLE) && ($new_retrial > 8)) { - $priority = PRIORITY_NEGLIGIBLE; + if (($priority < self::PRIORITY_MEDIUM) && ($new_retrial > 3)) { + $priority = self::PRIORITY_MEDIUM; + } elseif (($priority < self::PRIORITY_LOW) && ($new_retrial > 6)) { + $priority = self::PRIORITY_LOW; + } elseif (($priority < self::PRIORITY_NEGLIGIBLE) && ($new_retrial > 8)) { + $priority = self::PRIORITY_NEGLIGIBLE; } Logger::info('Deferred task', ['id' => $id, 'retrial' => $new_retrial, 'created' => $queue['created'], 'next_execution' => $next, 'old_prio' => $queue['priority'], 'new_prio' => $priority]); diff --git a/src/Core/Worker/Cron.php b/src/Core/Worker/Cron.php index 0f2c4b41e..11631e02b 100644 --- a/src/Core/Worker/Cron.php +++ b/src/Core/Worker/Cron.php @@ -47,10 +47,10 @@ class Cron Logger::info('Add cron entries'); // Check for spooled items - Worker::add(['priority' => PRIORITY_HIGH, 'force_priority' => true], 'SpoolPost'); + Worker::add(['priority' => Worker::PRIORITY_HIGH, 'force_priority' => true], 'SpoolPost'); // Run the cron job that calls all other jobs - Worker::add(['priority' => PRIORITY_MEDIUM, 'force_priority' => true], 'Cron'); + Worker::add(['priority' => Worker::PRIORITY_MEDIUM, 'force_priority' => true], 'Cron'); // Cleaning dead processes self::killStaleWorkers(); @@ -112,12 +112,12 @@ class Cron // To avoid a blocking situation we reschedule the process at the beginning of the queue. // Additionally we are lowering the priority. (But not PRIORITY_CRITICAL) $new_priority = $entry['priority']; - if ($entry['priority'] == PRIORITY_HIGH) { - $new_priority = PRIORITY_MEDIUM; - } elseif ($entry['priority'] == PRIORITY_MEDIUM) { - $new_priority = PRIORITY_LOW; - } elseif ($entry['priority'] != PRIORITY_CRITICAL) { - $new_priority = PRIORITY_NEGLIGIBLE; + if ($entry['priority'] == Worker::PRIORITY_HIGH) { + $new_priority = Worker::PRIORITY_MEDIUM; + } elseif ($entry['priority'] == Worker::PRIORITY_MEDIUM) { + $new_priority = Worker::PRIORITY_LOW; + } elseif ($entry['priority'] != Worker::PRIORITY_CRITICAL) { + $new_priority = Worker::PRIORITY_NEGLIGIBLE; } DBA::update('workerqueue', ['executed' => DBA::NULL_DATETIME, 'created' => DateTimeFormat::utcNow(), 'priority' => $new_priority, 'pid' => 0], ['id' => $entry["id"]] ); @@ -166,13 +166,13 @@ class Cron Logger::info('Directly deliver inbox', ['inbox' => $delivery['inbox'], 'result' => $result['success']]); continue; } elseif ($delivery['failed'] < 3) { - $priority = PRIORITY_HIGH; + $priority = Worker::PRIORITY_HIGH; } elseif ($delivery['failed'] < 6) { - $priority = PRIORITY_MEDIUM; + $priority = Worker::PRIORITY_MEDIUM; } elseif ($delivery['failed'] < 8) { - $priority = PRIORITY_LOW; + $priority = Worker::PRIORITY_LOW; } else { - $priority = PRIORITY_NEGLIGIBLE; + $priority = Worker::PRIORITY_NEGLIGIBLE; } if ($delivery['failed'] >= DI::config()->get('system', 'worker_defer_limit')) { diff --git a/src/Model/Contact.php b/src/Model/Contact.php index ceaf635df..434c2b1f6 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -319,7 +319,7 @@ class Contact // Update the contact in the background if needed if (Probe::isProbable($contact['network']) && ($contact['next-update'] < DateTimeFormat::utcNow())) { - Worker::add(['priority' => PRIORITY_LOW, 'dont_fork' => true], 'UpdateContact', $contact['id']); + Worker::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], 'UpdateContact', $contact['id']); } // Remove the internal fields @@ -884,7 +884,7 @@ class Contact } // Delete it in the background - Worker::add(PRIORITY_MEDIUM, 'Contact\Remove', $id); + Worker::add(Worker::PRIORITY_MEDIUM, 'Contact\Remove', $id); } /** @@ -908,7 +908,7 @@ class Contact if (in_array($contact['rel'], [self::SHARING, self::FRIEND])) { $cdata = self::getPublicAndUserContactID($contact['id'], $contact['uid']); if (!empty($cdata['public'])) { - Worker::add(PRIORITY_HIGH, 'Contact\Unfollow', $cdata['public'], $contact['uid']); + Worker::add(Worker::PRIORITY_HIGH, 'Contact\Unfollow', $cdata['public'], $contact['uid']); } } @@ -938,7 +938,7 @@ class Contact if (in_array($contact['rel'], [self::FOLLOWER, self::FRIEND])) { $cdata = self::getPublicAndUserContactID($contact['id'], $contact['uid']); if (!empty($cdata['public'])) { - Worker::add(PRIORITY_HIGH, 'Contact\RevokeFollow', $cdata['public'], $contact['uid']); + Worker::add(Worker::PRIORITY_HIGH, 'Contact\RevokeFollow', $cdata['public'], $contact['uid']); } } @@ -966,11 +966,11 @@ class Contact $cdata = self::getPublicAndUserContactID($contact['id'], $contact['uid']); if (in_array($contact['rel'], [self::SHARING, self::FRIEND]) && !empty($cdata['public'])) { - Worker::add(PRIORITY_HIGH, 'Contact\Unfollow', $cdata['public'], $contact['uid']); + Worker::add(Worker::PRIORITY_HIGH, 'Contact\Unfollow', $cdata['public'], $contact['uid']); } if (in_array($contact['rel'], [self::FOLLOWER, self::FRIEND]) && !empty($cdata['public'])) { - Worker::add(PRIORITY_HIGH, 'Contact\RevokeFollow', $cdata['public'], $contact['uid']); + Worker::add(Worker::PRIORITY_HIGH, 'Contact\RevokeFollow', $cdata['public'], $contact['uid']); } self::remove($contact['id']); @@ -1248,7 +1248,7 @@ class Contact $contact_id = $contact['id']; if (Probe::isProbable($contact['network']) && ($contact['next-update'] < DateTimeFormat::utcNow())) { - Worker::add(['priority' => PRIORITY_LOW, 'dont_fork' => true], 'UpdateContact', $contact['id']); + Worker::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], 'UpdateContact', $contact['id']); } if (empty($update) && (!empty($contact['uri-id']) || is_bool($update))) { @@ -2365,7 +2365,7 @@ class Contact return; } Logger::warning('account-user exists for a different contact id', ['account_user' => $account_user, 'id' => $id, 'uid' => $uid, 'uri-id' => $uri_id, 'url' => $url]); - Worker::add(PRIORITY_HIGH, 'MergeContact', $account_user['id'], $id, $uid); + Worker::add(Worker::PRIORITY_HIGH, 'MergeContact', $account_user['id'], $id, $uid); } elseif (DBA::insert('account-user', ['id' => $id, 'uri-id' => $uri_id, 'uid' => $uid], Database::INSERT_IGNORE)) { Logger::notice('account-user was added', ['id' => $id, 'uid' => $uid, 'uri-id' => $uri_id, 'url' => $url]); } else { @@ -2406,7 +2406,7 @@ class Contact continue; } - Worker::add(PRIORITY_HIGH, 'MergeContact', $first, $duplicate['id'], $uid); + Worker::add(Worker::PRIORITY_HIGH, 'MergeContact', $first, $duplicate['id'], $uid); } DBA::close($duplicates); Logger::info('Duplicates handled', ['uid' => $uid, 'nurl' => $nurl, 'callstack' => System::callstack(20)]); @@ -2608,7 +2608,7 @@ class Contact if ($ret['network'] == Protocol::ACTIVITYPUB) { $apcontact = APContact::getByURL($ret['url'], false); if (!empty($apcontact['featured'])) { - Worker::add(PRIORITY_LOW, 'FetchFeaturedPosts', $ret['url']); + Worker::add(Worker::PRIORITY_LOW, 'FetchFeaturedPosts', $ret['url']); } } @@ -2649,7 +2649,7 @@ class Contact self::updateContact($id, $uid, $uriid, $contact['url'], ['failed' => false, 'local-data' => $has_local_data, 'last-update' => $updated, 'next-update' => $success_next_update, 'success_update' => $updated]); if (Contact\Relation::isDiscoverable($ret['url'])) { - Worker::add(PRIORITY_LOW, 'ContactDiscovery', $ret['url']); + Worker::add(Worker::PRIORITY_LOW, 'ContactDiscovery', $ret['url']); } // Update the public contact @@ -2693,7 +2693,7 @@ class Contact self::updateContact($id, $uid, $ret['uri-id'], $ret['url'], $ret); if (Contact\Relation::isDiscoverable($ret['url'])) { - Worker::add(PRIORITY_LOW, 'ContactDiscovery', $ret['url']); + Worker::add(Worker::PRIORITY_LOW, 'ContactDiscovery', $ret['url']); } return true; @@ -2949,13 +2949,13 @@ class Contact // pull feed and consume it, which should subscribe to the hub. if ($contact['network'] == Protocol::OSTATUS) { - Worker::add(PRIORITY_HIGH, 'OnePoll', $contact_id, 'force'); + Worker::add(Worker::PRIORITY_HIGH, 'OnePoll', $contact_id, 'force'); } if ($probed) { self::updateFromProbeArray($contact_id, $ret); } else { - Worker::add(PRIORITY_HIGH, 'UpdateContact', $contact_id); + Worker::add(Worker::PRIORITY_HIGH, 'UpdateContact', $contact_id); } $result['success'] = Protocol::follow($uid, $contact, $protocol); @@ -3407,10 +3407,10 @@ class Contact } $contact = self::getByURL($url, false, ['id', 'network', 'next-update']); if (empty($contact['id']) && Network::isValidHttpUrl($url)) { - Worker::add(PRIORITY_LOW, 'AddContact', 0, $url); + Worker::add(Worker::PRIORITY_LOW, 'AddContact', 0, $url); ++$added; } elseif (!empty($contact['network']) && Probe::isProbable($contact['network']) && ($contact['next-update'] < DateTimeFormat::utcNow())) { - Worker::add(['priority' => PRIORITY_LOW, 'dont_fork' => true], 'UpdateContact', $contact['id']); + Worker::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], 'UpdateContact', $contact['id']); ++$updated; } else { ++$unchanged; diff --git a/src/Model/FContact.php b/src/Model/FContact.php index ae6c9cb31..fa21906bc 100644 --- a/src/Model/FContact.php +++ b/src/Model/FContact.php @@ -58,7 +58,7 @@ class FContact $update = empty($person['guid']) || empty($person['uri-id']) || ($person['created'] <= DBA::NULL_DATETIME); if (GServer::getNextUpdateDate(true, $person['created'], $person['updated'], false) < DateTimeFormat::utcNow()) { Logger::debug('Start background update', ['handle' => $handle]); - Worker::add(['priority' => PRIORITY_LOW, 'dont_fork' => true], 'UpdateFContact', $handle); + Worker::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], 'UpdateFContact', $handle); } } } elseif (is_null($update)) { diff --git a/src/Model/GServer.php b/src/Model/GServer.php index ac8a84327..7e4b055d1 100644 --- a/src/Model/GServer.php +++ b/src/Model/GServer.php @@ -102,7 +102,7 @@ class GServer return; } - Worker::add(PRIORITY_LOW, 'UpdateGServer', $url, $only_nodeinfo); + Worker::add(Worker::PRIORITY_LOW, 'UpdateGServer', $url, $only_nodeinfo); } /** @@ -2108,10 +2108,10 @@ class GServer while ($gserver = DBA::fetch($gservers)) { Logger::info('Update peer list', ['server' => $gserver['url'], 'id' => $gserver['id']]); - Worker::add(PRIORITY_LOW, 'UpdateServerPeers', $gserver['url']); + Worker::add(Worker::PRIORITY_LOW, 'UpdateServerPeers', $gserver['url']); Logger::info('Update directory', ['server' => $gserver['url'], 'id' => $gserver['id']]); - Worker::add(PRIORITY_LOW, 'UpdateServerDirectory', $gserver); + Worker::add(Worker::PRIORITY_LOW, 'UpdateServerDirectory', $gserver); $fields = ['last_poco_query' => DateTimeFormat::utcNow()]; self::update($fields, ['nurl' => $gserver['nurl']]); diff --git a/src/Model/Item.php b/src/Model/Item.php index 3270d170b..130a1c463 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -232,7 +232,7 @@ class Item foreach ($notify_items as $notify_item) { $post = Post::selectFirst(['uri-id', 'uid'], ['id' => $notify_item]); - Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::POST, (int)$post['uri-id'], (int)$post['uid']); + Worker::add(Worker::PRIORITY_HIGH, 'Notifier', Delivery::POST, (int)$post['uri-id'], (int)$post['uid']); } return $rows; @@ -246,7 +246,7 @@ class Item * @return void * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function markForDeletion(array $condition, int $priority = PRIORITY_HIGH) + public static function markForDeletion(array $condition, int $priority = Worker::PRIORITY_HIGH) { $items = Post::select(['id'], $condition); while ($item = Post::fetch($items)) { @@ -277,7 +277,7 @@ class Item } if ($item['uid'] == $uid) { - self::markForDeletionById($item['id'], PRIORITY_HIGH); + self::markForDeletionById($item['id'], Worker::PRIORITY_HIGH); } elseif ($item['uid'] != 0) { Logger::warning('Wrong ownership. Not deleting item', ['id' => $item['id']]); } @@ -293,7 +293,7 @@ class Item * @return boolean success * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function markForDeletionById(int $item_id, int $priority = PRIORITY_HIGH): bool + public static function markForDeletionById(int $item_id, int $priority = Worker::PRIORITY_HIGH): bool { Logger::info('Mark item for deletion by id', ['id' => $item_id, 'callstack' => System::callstack()]); // locate item to be deleted @@ -816,7 +816,7 @@ class Item { $orig_item = $item; - $priority = PRIORITY_HIGH; + $priority = Worker::PRIORITY_HIGH; // If it is a posting where users should get notifications, then define it as wall posting if ($notify) { @@ -826,7 +826,7 @@ class Item $item['protocol'] = Conversation::PARCEL_DIRECT; $item['direction'] = Conversation::PUSH; - if (is_int($notify) && in_array($notify, PRIORITIES)) { + if (is_int($notify) && in_array($notify, Worker::PRIORITIES)) { $priority = $notify; } } else { diff --git a/src/Model/Mail.php b/src/Model/Mail.php index e494119cb..cdcd2258c 100644 --- a/src/Model/Mail.php +++ b/src/Model/Mail.php @@ -239,7 +239,7 @@ class Mail } if ($post_id) { - Worker::add(PRIORITY_HIGH, "Notifier", Delivery::MAIL, $post_id); + Worker::add(Worker::PRIORITY_HIGH, "Notifier", Delivery::MAIL, $post_id); return intval($post_id); } else { return -3; diff --git a/src/Model/Post/Delayed.php b/src/Model/Post/Delayed.php index 1f15f26b9..3f96af698 100644 --- a/src/Model/Post/Delayed.php +++ b/src/Model/Post/Delayed.php @@ -80,7 +80,7 @@ class Delayed Logger::notice('Adding post for delayed publishing', ['uid' => $item['uid'], 'delayed' => $delayed, 'uri' => $uri]); - $wid = Worker::add(['priority' => PRIORITY_HIGH, 'delayed' => $delayed], 'DelayedPublish', $item, $notify, $taglist, $attachments, $preparation_mode, $uri); + $wid = Worker::add(['priority' => Worker::PRIORITY_HIGH, 'delayed' => $delayed], 'DelayedPublish', $item, $notify, $taglist, $attachments, $preparation_mode, $uri); if (!$wid) { return 0; } diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 094df729e..f6d189a10 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -153,11 +153,11 @@ class Profile if ($owner['net-publish'] || $force) { // Update global directory in background if (Search::getGlobalDirectory()) { - Worker::add(PRIORITY_LOW, 'Directory', $owner['url']); + Worker::add(Worker::PRIORITY_LOW, 'Directory', $owner['url']); } } - Worker::add(PRIORITY_LOW, 'ProfileUpdate', $uid); + Worker::add(Worker::PRIORITY_LOW, 'ProfileUpdate', $uid); } /** diff --git a/src/Model/PushSubscriber.php b/src/Model/PushSubscriber.php index 8aa67eee5..5b6c8813a 100644 --- a/src/Model/PushSubscriber.php +++ b/src/Model/PushSubscriber.php @@ -37,7 +37,7 @@ class PushSubscriber * @return void * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function publishFeed(int $uid, int $default_priority = PRIORITY_HIGH) + public static function publishFeed(int $uid, int $default_priority = Worker::PRIORITY_HIGH) { $condition = ['push' => 0, 'uid' => $uid]; DBA::update('push_subscriber', ['push' => 1, 'next_try' => DBA::NULL_DATETIME], $condition); @@ -52,7 +52,7 @@ class PushSubscriber * @return void * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function requeue(int $default_priority = PRIORITY_HIGH) + public static function requeue(int $default_priority = Worker::PRIORITY_HIGH) { // We'll push to each subscriber that has push > 0, // i.e. there has been an update (set in notifier.php). @@ -61,7 +61,7 @@ class PushSubscriber while ($subscriber = DBA::fetch($subscribers)) { // We always handle retries with low priority if ($subscriber['push'] > 1) { - $priority = PRIORITY_LOW; + $priority = Worker::PRIORITY_LOW; } else { $priority = $default_priority; } diff --git a/src/Model/Subscription.php b/src/Model/Subscription.php index 26617f941..2796b37a0 100644 --- a/src/Model/Subscription.php +++ b/src/Model/Subscription.php @@ -152,7 +152,7 @@ class Subscription $subscriptions = DBA::select('subscription', [], ['uid' => $notification->uid, $type => true]); while ($subscription = DBA::fetch($subscriptions)) { Logger::info('Push notification', ['id' => $subscription['id'], 'uid' => $subscription['uid'], 'type' => $type]); - Worker::add(PRIORITY_HIGH, 'PushSubscription', $subscription['id'], $notification->id); + Worker::add(Worker::PRIORITY_HIGH, 'PushSubscription', $subscription['id'], $notification->id); } DBA::close($subscriptions); } diff --git a/src/Model/User.php b/src/Model/User.php index 574830603..5bd84466f 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -1317,7 +1317,7 @@ class User if (DBA::isResult($profile) && $profile['net-publish'] && Search::getGlobalDirectory()) { $url = DI::baseUrl() . '/profile/' . $user['nickname']; - Worker::add(PRIORITY_LOW, "Directory", $url); + Worker::add(Worker::PRIORITY_LOW, "Directory", $url); } $l10n = DI::l10n()->withLang($register['language']); @@ -1567,14 +1567,14 @@ class User // The user and related data will be deleted in Friendica\Worker\ExpireAndRemoveUsers DBA::update('user', ['account_removed' => true, 'account_expires_on' => DateTimeFormat::utc('now + 7 day')], ['uid' => $uid]); - Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::REMOVAL, $uid); + Worker::add(Worker::PRIORITY_HIGH, 'Notifier', Delivery::REMOVAL, $uid); // Send an update to the directory $self = DBA::selectFirst('contact', ['url'], ['uid' => $uid, 'self' => true]); - Worker::add(PRIORITY_LOW, 'Directory', $self['url']); + Worker::add(Worker::PRIORITY_LOW, 'Directory', $self['url']); // Remove the user relevant data - Worker::add(PRIORITY_NEGLIGIBLE, 'RemoveUser', $uid); + Worker::add(Worker::PRIORITY_NEGLIGIBLE, 'RemoveUser', $uid); return true; } diff --git a/src/Module/Admin/Blocklist/Contact.php b/src/Module/Admin/Blocklist/Contact.php index ac1406c7f..35a8a151d 100644 --- a/src/Module/Admin/Blocklist/Contact.php +++ b/src/Module/Admin/Blocklist/Contact.php @@ -59,7 +59,7 @@ class Contact extends BaseAdmin if ($block_purge) { foreach (Model\Contact::selectToArray(['id'], ['nurl' => $contact['nurl']]) as $contact) { - Worker::add(PRIORITY_LOW, 'Contact\RemoveContent', $contact['id']); + Worker::add(Worker::PRIORITY_LOW, 'Contact\RemoveContent', $contact['id']); } } diff --git a/src/Module/Admin/Blocklist/Server/Add.php b/src/Module/Admin/Blocklist/Server/Add.php index a4aaa4b65..f060bcd06 100644 --- a/src/Module/Admin/Blocklist/Server/Add.php +++ b/src/Module/Admin/Blocklist/Server/Add.php @@ -82,7 +82,7 @@ class Add extends BaseAdmin if (!empty($request['purge'])) { $gservers = GServer::listByDomainPattern($pattern); foreach (Contact::selectToArray(['id'], ['gsid' => array_column($gservers, 'id')]) as $contact) { - Worker::add(PRIORITY_LOW, 'Contact\RemoveContent', $contact['id']); + Worker::add(Worker::PRIORITY_LOW, 'Contact\RemoveContent', $contact['id']); } $this->sysmsg->addInfo($this->l10n->tt('%s server scheduled to be purged.', '%s servers scheduled to be purged.', count($gservers))); diff --git a/src/Module/Admin/Site.php b/src/Module/Admin/Site.php index fbebfcb3f..37d8ed040 100644 --- a/src/Module/Admin/Site.php +++ b/src/Module/Admin/Site.php @@ -53,7 +53,7 @@ class Site extends BaseAdmin $a = DI::app(); if (!empty($_POST['republish_directory'])) { - Worker::add(PRIORITY_LOW, 'Directory'); + Worker::add(Worker::PRIORITY_LOW, 'Directory'); return; } @@ -150,7 +150,7 @@ class Site extends BaseAdmin // Has the directory url changed? If yes, then resubmit the existing profiles there if ($global_directory != DI::config()->get('system', 'directory') && ($global_directory != '')) { DI::config()->set('system', 'directory', $global_directory); - Worker::add(PRIORITY_LOW, 'Directory'); + Worker::add(Worker::PRIORITY_LOW, 'Directory'); } if (DI::baseUrl()->getUrlPath() != "") { diff --git a/src/Module/Api/Friendica/Events/Create.php b/src/Module/Api/Friendica/Events/Create.php index 8a8f13b50..8c6ec8f63 100644 --- a/src/Module/Api/Friendica/Events/Create.php +++ b/src/Module/Api/Friendica/Events/Create.php @@ -104,7 +104,7 @@ class Create extends BaseApi $item = ['network' => Protocol::DFRN, 'protocol' => Conversation::PARCEL_DIRECT, 'direction' => Conversation::PUSH]; $item = Event::getItemArrayForId($event_id, $item); if (Item::insert($item)) { - Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, (int)$item['uri-id'], $uid); + Worker::add(Worker::PRIORITY_HIGH, "Notifier", Delivery::POST, (int)$item['uri-id'], $uid); } } diff --git a/src/Module/Api/Mastodon/Statuses.php b/src/Module/Api/Mastodon/Statuses.php index 4a8c98697..8cc3e3ddf 100644 --- a/src/Module/Api/Mastodon/Statuses.php +++ b/src/Module/Api/Mastodon/Statuses.php @@ -25,6 +25,7 @@ use Friendica\App\Router; use Friendica\Content\Text\Markdown; use Friendica\Core\Protocol; use Friendica\Core\System; +use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; @@ -204,7 +205,7 @@ class Statuses extends BaseApi if (!empty($request['scheduled_at'])) { $item['guid'] = Item::guid($item, true); $item['uri'] = Item::newURI($item['guid']); - $id = Post\Delayed::add($item['uri'], $item, PRIORITY_HIGH, Post\Delayed::PREPARED, $request['scheduled_at']); + $id = Post\Delayed::add($item['uri'], $item, Worker::PRIORITY_HIGH, Post\Delayed::PREPARED, $request['scheduled_at']); if (empty($id)) { DI::mstdnError()->InternalError(); } diff --git a/src/Module/Contact.php b/src/Module/Contact.php index 9c073b3ef..4f565a871 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -126,9 +126,9 @@ class Contact extends BaseModule } // pull feed and consume it, which should subscribe to the hub. - Worker::add(PRIORITY_HIGH, 'OnePoll', $contact_id, 'force'); + Worker::add(Worker::PRIORITY_HIGH, 'OnePoll', $contact_id, 'force'); } else { - Worker::add(PRIORITY_HIGH, 'UpdateContact', $contact_id); + Worker::add(Worker::PRIORITY_HIGH, 'UpdateContact', $contact_id); } } diff --git a/src/Module/FriendSuggest.php b/src/Module/FriendSuggest.php index 3cebd72ce..d8a42d8de 100644 --- a/src/Module/FriendSuggest.php +++ b/src/Module/FriendSuggest.php @@ -94,7 +94,7 @@ class FriendSuggest extends BaseModule $note )); - Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::SUGGESTION, $suggest->id); + Worker::add(Worker::PRIORITY_HIGH, 'Notifier', Delivery::SUGGESTION, $suggest->id); info($this->t('Friend suggestion sent.')); } diff --git a/src/Module/Photo.php b/src/Module/Photo.php index 076dc8107..5fdabd33c 100644 --- a/src/Module/Photo.php +++ b/src/Module/Photo.php @@ -338,7 +338,7 @@ class Photo extends BaseModule } if ($update) { Logger::info('Invalid file, contact update initiated', ['cid' => $id, 'url' => $contact['url'], 'avatar' => $url]); - Worker::add(PRIORITY_LOW, 'UpdateContact', $id); + Worker::add(Worker::PRIORITY_LOW, 'UpdateContact', $id); } else { Logger::info('Invalid file', ['cid' => $id, 'url' => $contact['url'], 'avatar' => $url]); } diff --git a/src/Module/Register.php b/src/Module/Register.php index 9c09baef8..95cea1458 100644 --- a/src/Module/Register.php +++ b/src/Module/Register.php @@ -302,7 +302,7 @@ class Register extends BaseModule if ($netpublish && intval(DI::config()->get('config', 'register_policy')) !== self::APPROVE) { $url = $base_url . '/profile/' . $user['nickname']; - Worker::add(PRIORITY_LOW, 'Directory', $url); + Worker::add(Worker::PRIORITY_LOW, 'Directory', $url); } if ($additional_account) { diff --git a/src/Module/Settings/Account.php b/src/Module/Settings/Account.php index 373f1614d..62ad08a4c 100644 --- a/src/Module/Settings/Account.php +++ b/src/Module/Settings/Account.php @@ -375,7 +375,7 @@ class Account extends BaseSettings // "http" or "@" to be present in the string. // All other fields from the row will be ignored if ((strpos($csvRow[0], '@') !== false) || Network::isValidHttpUrl($csvRow[0])) { - Worker::add(PRIORITY_MEDIUM, 'AddContact', local_user(), $csvRow[0]); + Worker::add(Worker::PRIORITY_MEDIUM, 'AddContact', local_user(), $csvRow[0]); } else { Logger::notice('Invalid account', ['url' => $csvRow[0]]); } @@ -394,7 +394,7 @@ class Account extends BaseSettings } if (!empty($request['relocate-submit'])) { - Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::RELOCATION, local_user()); + Worker::add(Worker::PRIORITY_HIGH, 'Notifier', Delivery::RELOCATION, local_user()); info(DI::l10n()->t("Relocate message has been send to your contacts")); DI::baseUrl()->redirect($redirectUrl); } diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index 04ea02f80..bb4d61b5a 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -552,7 +552,7 @@ class Processor Logger::notice('Fetching is done by worker.', ['parent' => $activity['reply-to-id'], 'recursion-depth' => $recursion_depth]); Fetch::add($activity['reply-to-id']); $activity['recursion-depth'] = 0; - $wid = Worker::add(PRIORITY_HIGH, 'FetchMissingActivity', $activity['reply-to-id'], $activity, '', Receiver::COMPLETION_AUTO); + $wid = Worker::add(Worker::PRIORITY_HIGH, 'FetchMissingActivity', $activity['reply-to-id'], $activity, '', Receiver::COMPLETION_AUTO); Fetch::setWorkerId($activity['reply-to-id'], $wid); } else { Logger::debug('Activity will already be fetched via a worker.', ['url' => $activity['reply-to-id']]); @@ -1665,9 +1665,9 @@ class Processor } if (DI::config()->get('system', 'bulk_delivery')) { Post\Delivery::add($post['uri-id'], $uid, $inbox, $post['created'], Delivery::POST, [$cid]); - Worker::add(PRIORITY_HIGH, 'APDelivery', '', 0, $inbox, 0); + Worker::add(Worker::PRIORITY_HIGH, 'APDelivery', '', 0, $inbox, 0); } else { - Worker::add(PRIORITY_HIGH, 'APDelivery', Delivery::POST, $post['id'], $inbox, $uid, [$cid], $post['uri-id']); + Worker::add(Worker::PRIORITY_HIGH, 'APDelivery', Delivery::POST, $post['id'], $inbox, $uid, [$cid], $post['uri-id']); } } } diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php index 30348c7ad..1ecfaf6aa 100644 --- a/src/Protocol/ActivityPub/Receiver.php +++ b/src/Protocol/ActivityPub/Receiver.php @@ -652,7 +652,7 @@ class Receiver // We delay by 5 seconds to allow to accumulate all receivers $delayed = date(DateTimeFormat::MYSQL, time() + 5); Logger::debug('Initiate processing', ['id' => $object_data['entry-id'], 'uri' => $object_data['object_id']]); - $wid = Worker::add(['priority' => PRIORITY_HIGH, 'delayed' => $delayed], 'ProcessQueue', $object_data['entry-id']); + $wid = Worker::add(['priority' => Worker::PRIORITY_HIGH, 'delayed' => $delayed], 'ProcessQueue', $object_data['entry-id']); Queue::setWorkerId($object_data['entry-id'], $wid); } else { Logger::debug('Other queue entries need to be processed first.', ['id' => $object_data['entry-id']]); diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 66ace1d3d..a2c17f478 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -2020,7 +2020,7 @@ class Diaspora } Logger::info('Deliver participation', ['item' => $comment['id'], 'contact' => $author_contact['cid']]); - if (Worker::add(PRIORITY_HIGH, 'Delivery', Delivery::POST, $comment['uri-id'], $author_contact['cid'], $datarray['uid'])) { + if (Worker::add(Worker::PRIORITY_HIGH, 'Delivery', Delivery::POST, $comment['uri-id'], $author_contact['cid'], $datarray['uid'])) { Post\DeliveryData::incrementQueueCount($comment['uri-id'], 1); } } diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index 7ff86c1db..f1521ac2d 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -30,6 +30,7 @@ use Friendica\Content\Text\HTML; use Friendica\Core\Cache\Enum\Duration; use Friendica\Core\Logger; use Friendica\Core\Protocol; +use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; @@ -630,7 +631,7 @@ class Feed unset($item['parent-uri']); // Set the delivery priority for "remote self" to "medium" - $notify = PRIORITY_MEDIUM; + $notify = Worker::PRIORITY_MEDIUM; } $condition = ['uid' => $item['uid'], 'uri' => $item['uri']]; diff --git a/src/Worker/CheckDeletedContacts.php b/src/Worker/CheckDeletedContacts.php index 4d1c3b637..f612cd2ee 100644 --- a/src/Worker/CheckDeletedContacts.php +++ b/src/Worker/CheckDeletedContacts.php @@ -34,7 +34,7 @@ class CheckDeletedContacts { $contacts = DBA::select('contact', ['id'], ['deleted' => true]); while ($contact = DBA::fetch($contacts)) { - Worker::add(PRIORITY_MEDIUM, 'Contact\Remove', $contact['id']); + Worker::add(Worker::PRIORITY_MEDIUM, 'Contact\Remove', $contact['id']); } DBA::close($contacts); } diff --git a/src/Worker/Cron.php b/src/Worker/Cron.php index 12ea6e60a..21d2f8a20 100644 --- a/src/Worker/Cron.php +++ b/src/Worker/Cron.php @@ -62,25 +62,25 @@ class Cron } // Fork the cron jobs in separate parts to avoid problems when one of them is crashing - Hook::fork(PRIORITY_MEDIUM, 'cron'); + Hook::fork(Worker::PRIORITY_MEDIUM, 'cron'); // Poll contacts - Worker::add(PRIORITY_MEDIUM, 'PollContacts'); + Worker::add(Worker::PRIORITY_MEDIUM, 'PollContacts'); // Update contact information - Worker::add(PRIORITY_LOW, 'UpdateContacts'); + Worker::add(Worker::PRIORITY_LOW, 'UpdateContacts'); // Update server information - Worker::add(PRIORITY_LOW, 'UpdateGServers'); + Worker::add(Worker::PRIORITY_LOW, 'UpdateGServers'); // run the process to update server directories in the background - Worker::add(PRIORITY_LOW, 'UpdateServerDirectories'); + Worker::add(Worker::PRIORITY_LOW, 'UpdateServerDirectories'); // Expire and remove user entries - Worker::add(PRIORITY_MEDIUM, 'ExpireAndRemoveUsers'); + Worker::add(Worker::PRIORITY_MEDIUM, 'ExpireAndRemoveUsers'); // Call possible post update functions - Worker::add(PRIORITY_LOW, 'PostUpdate'); + Worker::add(Worker::PRIORITY_LOW, 'PostUpdate'); // Hourly cron calls if (DI::config()->get('system', 'last_cron_hourly', 0) + 3600 < time()) { @@ -97,11 +97,11 @@ class Cron // Search for new contacts in the directory if (DI::config()->get('system', 'synchronize_directory')) { - Worker::add(PRIORITY_LOW, 'PullDirectory'); + Worker::add(Worker::PRIORITY_LOW, 'PullDirectory'); } // Clear cache entries - Worker::add(PRIORITY_LOW, 'ClearCache'); + Worker::add(Worker::PRIORITY_LOW, 'ClearCache'); DI::config()->set('system', 'last_cron_hourly', time()); } @@ -109,27 +109,27 @@ class Cron // Daily maintenance cron calls if (Worker::isInMaintenanceWindow(true)) { - Worker::add(PRIORITY_LOW, 'UpdateContactBirthdays'); + Worker::add(Worker::PRIORITY_LOW, 'UpdateContactBirthdays'); - Worker::add(PRIORITY_LOW, 'UpdatePhotoAlbums'); + Worker::add(Worker::PRIORITY_LOW, 'UpdatePhotoAlbums'); - Worker::add(PRIORITY_LOW, 'ExpirePosts'); + Worker::add(Worker::PRIORITY_LOW, 'ExpirePosts'); - Worker::add(PRIORITY_LOW, 'ExpireActivities'); + Worker::add(Worker::PRIORITY_LOW, 'ExpireActivities'); - Worker::add(PRIORITY_LOW, 'RemoveUnusedTags'); + Worker::add(Worker::PRIORITY_LOW, 'RemoveUnusedTags'); - Worker::add(PRIORITY_LOW, 'RemoveUnusedContacts'); + Worker::add(Worker::PRIORITY_LOW, 'RemoveUnusedContacts'); - Worker::add(PRIORITY_LOW, 'RemoveUnusedAvatars'); + Worker::add(Worker::PRIORITY_LOW, 'RemoveUnusedAvatars'); // check upstream version? - Worker::add(PRIORITY_LOW, 'CheckVersion'); + Worker::add(Worker::PRIORITY_LOW, 'CheckVersion'); - Worker::add(PRIORITY_LOW, 'CheckDeletedContacts'); + Worker::add(Worker::PRIORITY_LOW, 'CheckDeletedContacts'); if (DI::config()->get('system', 'optimize_tables')) { - Worker::add(PRIORITY_LOW, 'OptimizeTables'); + Worker::add(Worker::PRIORITY_LOW, 'OptimizeTables'); } // Resubscribe to relay servers diff --git a/src/Worker/Directory.php b/src/Worker/Directory.php index bb8041a22..f0ee2ab5d 100644 --- a/src/Worker/Directory.php +++ b/src/Worker/Directory.php @@ -64,7 +64,7 @@ class Directory private static function updateAll() { $users = DBA::select('owner-view', ['url'], ['net-publish' => true, 'account_expired' => false, 'verified' => true]); while ($user = DBA::fetch($users)) { - Worker::add(PRIORITY_LOW, 'Directory', $user['url']); + Worker::add(Worker::PRIORITY_LOW, 'Directory', $user['url']); } DBA::close($users); } diff --git a/src/Worker/ExpirePosts.php b/src/Worker/ExpirePosts.php index bbdfaa42c..ffb40e697 100644 --- a/src/Worker/ExpirePosts.php +++ b/src/Worker/ExpirePosts.php @@ -53,10 +53,10 @@ class ExpirePosts } // Set the expiry for origin posta - Worker::add(PRIORITY_LOW, 'Expire'); + Worker::add(Worker::PRIORITY_LOW, 'Expire'); // update nodeinfo data after everything is cleaned up - Worker::add(PRIORITY_LOW, 'NodeInfo'); + Worker::add(Worker::PRIORITY_LOW, 'NodeInfo'); } /** diff --git a/src/Worker/MoveStorage.php b/src/Worker/MoveStorage.php index 4b24caf5b..30f42e40c 100644 --- a/src/Worker/MoveStorage.php +++ b/src/Worker/MoveStorage.php @@ -37,7 +37,7 @@ class MoveStorage $moved = DI::storageManager()->move($current); if ($moved) { - Worker::add(PRIORITY_LOW, 'MoveStorage'); + Worker::add(Worker::PRIORITY_LOW, 'MoveStorage'); } } } diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 7d3d3d6b7..45dc4de30 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -86,7 +86,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' => PRIORITY_HIGH, 'created' => $a->getQueueValue('created'), 'dont_fork' => true], + Worker::add(['priority' => Worker::PRIORITY_HIGH, 'created' => $a->getQueueValue('created'), 'dont_fork' => true], 'APDelivery', $cmd, $target_id, $inbox, $uid, $receivers, $post_uriid); } } elseif ($cmd == Delivery::SUGGESTION) { @@ -568,7 +568,7 @@ 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'), [PRIORITY_HIGH, PRIORITY_MEDIUM])) { + 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]; } else { $deliver_options = ['priority' => $a->getQueueValue('priority'), 'created' => $a->getQueueValue('created'), 'dont_fork' => true]; @@ -698,7 +698,7 @@ class Notifier $inboxes = ActivityPub\Transmitter::fetchTargetInboxesforUser($self_user_id); foreach ($inboxes as $inbox => $receivers) { Logger::info('Account removal via ActivityPub', ['uid' => $self_user_id, 'inbox' => $inbox]); - Worker::add(['priority' => PRIORITY_NEGLIGIBLE, 'created' => $created, 'dont_fork' => true], + Worker::add(['priority' => Worker::PRIORITY_NEGLIGIBLE, 'created' => $created, 'dont_fork' => true], 'APDelivery', Delivery::REMOVAL, 0, $inbox, $self_user_id, $receivers); Worker::coolDown(); } @@ -817,7 +817,7 @@ class Notifier if (DI::config()->get('system', 'bulk_delivery')) { $delivery_queue_count++; Post\Delivery::add($target_item['uri-id'], $uid, $inbox, $target_item['created'], $cmd, $receivers); - Worker::add(PRIORITY_HIGH, 'APDelivery', '', 0, $inbox, 0); + Worker::add(Worker::PRIORITY_HIGH, 'APDelivery', '', 0, $inbox, 0); } else { if (Worker::add(['priority' => $priority, 'created' => $created, 'dont_fork' => true], 'APDelivery', $cmd, $target_item['id'], $inbox, $uid, $receivers, $target_item['uri-id'])) { @@ -834,7 +834,7 @@ class Notifier if (DI::config()->get('system', 'bulk_delivery')) { $delivery_queue_count++; Post\Delivery::add($target_item['uri-id'], $uid, $inbox, $target_item['created'], $cmd, []); - Worker::add(PRIORITY_MEDIUM, 'APDelivery', '', 0, $inbox, 0); + Worker::add(Worker::PRIORITY_MEDIUM, 'APDelivery', '', 0, $inbox, 0); } else { if (Worker::add(['priority' => $priority, 'dont_fork' => true], 'APDelivery', $cmd, $target_item['id'], $inbox, $uid, [], $target_item['uri-id'])) { $delivery_queue_count++; diff --git a/src/Worker/PollContacts.php b/src/Worker/PollContacts.php index b4312ef0c..454b5a9ae 100644 --- a/src/Worker/PollContacts.php +++ b/src/Worker/PollContacts.php @@ -71,11 +71,11 @@ class PollContacts } if ((($contact['network'] == Protocol::FEED) && ($contact['priority'] <= 3)) || ($contact['network'] == Protocol::MAIL)) { - $priority = PRIORITY_MEDIUM; + $priority = Worker::PRIORITY_MEDIUM; } elseif ($contact['archive']) { - $priority = PRIORITY_NEGLIGIBLE; + $priority = Worker::PRIORITY_NEGLIGIBLE; } else { - $priority = PRIORITY_LOW; + $priority = Worker::PRIORITY_LOW; } Logger::notice("Polling " . $contact["network"] . " " . $contact["id"] . " " . $contact['priority'] . " " . $contact["nick"] . " " . $contact["name"]); diff --git a/src/Worker/RemoveUser.php b/src/Worker/RemoveUser.php index 6a2d54422..72ead5264 100644 --- a/src/Worker/RemoveUser.php +++ b/src/Worker/RemoveUser.php @@ -21,6 +21,7 @@ namespace Friendica\Worker; +use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\Model\Item; use Friendica\Model\Post; @@ -48,7 +49,7 @@ class RemoveUser { do { $items = Post::select(['id'], $condition, ['limit' => 100]); while ($item = Post::fetch($items)) { - Item::markForDeletionById($item['id'], PRIORITY_NEGLIGIBLE); + Item::markForDeletionById($item['id'], Worker::PRIORITY_NEGLIGIBLE); } DBA::close($items); } while (Post::exists($condition)); diff --git a/src/Worker/UpdateContacts.php b/src/Worker/UpdateContacts.php index 7e352a27c..ed4a9932f 100644 --- a/src/Worker/UpdateContacts.php +++ b/src/Worker/UpdateContacts.php @@ -59,7 +59,7 @@ class UpdateContacts $contacts = DBA::select('contact', ['id'], $condition, ['order' => ['next-update'], 'limit' => $limit]); $count = 0; while ($contact = DBA::fetch($contacts)) { - if (Worker::add(['priority' => PRIORITY_LOW, 'dont_fork' => true], "UpdateContact", $contact['id'])) { + if (Worker::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], "UpdateContact", $contact['id'])) { ++$count; } Worker::coolDown(); diff --git a/src/Worker/UpdateGServers.php b/src/Worker/UpdateGServers.php index 108482eae..25a2db16e 100644 --- a/src/Worker/UpdateGServers.php +++ b/src/Worker/UpdateGServers.php @@ -63,12 +63,12 @@ class UpdateGServers // There are duplicated "url" but not "nurl". So we check both addresses instead of just overwriting them, // since that would mean loosing data. if (!empty($gserver['url'])) { - if (Worker::add(PRIORITY_LOW, 'UpdateGServer', $gserver['url'])) { + if (Worker::add(Worker::PRIORITY_LOW, 'UpdateGServer', $gserver['url'])) { $count++; } } if (!empty($gserver['nurl']) && ($gserver['nurl'] != Strings::normaliseLink($gserver['url']))) { - if (Worker::add(PRIORITY_LOW, 'UpdateGServer', $gserver['nurl'])) { + if (Worker::add(Worker::PRIORITY_LOW, 'UpdateGServer', $gserver['nurl'])) { $count++; } } diff --git a/static/defaults.config.php b/static/defaults.config.php index f20b333dd..647fb73b1 100644 --- a/static/defaults.config.php +++ b/static/defaults.config.php @@ -284,7 +284,7 @@ return [ // expire-notify-priority (integer) // Priority for the expirary notification - 'expire-notify-priority' => PRIORITY_LOW, + 'expire-notify-priority' => Friendica\Core\Worker::PRIORITY_LOW, // fetch_by_worker (Boolean) // Fetch missing posts via a background process diff --git a/update.php b/update.php index fab51993c..9f348efe6 100644 --- a/update.php +++ b/update.php @@ -131,7 +131,7 @@ function update_1309() continue; } - $deliver_options = ['priority' => PRIORITY_MEDIUM, 'dont_fork' => true]; + $deliver_options = ['priority' => Worker::PRIORITY_MEDIUM, 'dont_fork' => true]; Worker::add($deliver_options, 'Delivery', Delivery::POST, $item['id'], $entry['cid']); Logger::info('Added delivery worker', ['item' => $item['id'], 'contact' => $entry['cid']]); DBA::delete('queue', ['id' => $entry['id']]); @@ -152,7 +152,7 @@ function update_1318() DBA::update('profile', ['marital' => 'In a relation'], ['marital' => 'Unavailable']); DBA::update('profile', ['marital' => 'Single'], ['marital' => 'Available']); - Worker::add(PRIORITY_LOW, 'ProfileUpdate'); + Worker::add(Worker::PRIORITY_LOW, 'ProfileUpdate'); return Update::SUCCESS; }