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);
}
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');
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;
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);
}
}
$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();
}
$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;
}
// 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;
}
*/
self::run($basePath);
} else {
- Worker::add(PRIORITY_CRITICAL, 'DBUpdate');
+ Worker::add(Worker::PRIORITY_CRITICAL, 'DBUpdate');
}
}
}
}
// 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');
*/
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.
$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;
}
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()])) {
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 = [];
* @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
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();
$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
$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]);
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();
// 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"]]
);
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')) {
// 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
}
// Delete it in the background
- Worker::add(PRIORITY_MEDIUM, 'Contact\Remove', $id);
+ Worker::add(Worker::PRIORITY_MEDIUM, 'Contact\Remove', $id);
}
/**
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']);
}
}
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']);
}
}
$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']);
$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))) {
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 {
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)]);
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']);
}
}
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
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;
// 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);
}
$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;
$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)) {
return;
}
- Worker::add(PRIORITY_LOW, 'UpdateGServer', $url, $only_nodeinfo);
+ Worker::add(Worker::PRIORITY_LOW, 'UpdateGServer', $url, $only_nodeinfo);
}
/**
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']]);
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;
* @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)) {
}
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']]);
}
* @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
{
$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) {
$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 {
}
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;
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;
}
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);
}
/**
* @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);
* @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).
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;
}
$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);
}
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']);
// 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;
}
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']);
}
}
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)));
$a = DI::app();
if (!empty($_POST['republish_directory'])) {
- Worker::add(PRIORITY_LOW, 'Directory');
+ Worker::add(Worker::PRIORITY_LOW, 'Directory');
return;
}
// 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() != "") {
$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);
}
}
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;
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();
}
}
// 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);
}
}
$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.'));
}
}
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]);
}
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) {
// "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]]);
}
}
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);
}
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']]);
}
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']);
}
}
}
// 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']]);
}
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);
}
}
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;
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']];
{
$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);
}
}
// 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()) {
// 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());
}
// 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
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);
}
}
// 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');
}
/**
$moved = DI::storageManager()->move($current);
if ($moved) {
- Worker::add(PRIORITY_LOW, 'MoveStorage');
+ Worker::add(Worker::PRIORITY_LOW, 'MoveStorage');
}
}
}
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) {
// 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];
$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();
}
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'])) {
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++;
}
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"]);
namespace Friendica\Worker;
+use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\Model\Item;
use Friendica\Model\Post;
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));
$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();
// 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++;
}
}
// 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
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']]);
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;
}