The frontend worker is removed

This commit is contained in:
Michael 2021-01-01 23:05:26 +00:00
parent 9a6141dcbe
commit a81ac835a1
10 changed files with 8 additions and 220 deletions

View file

@ -205,9 +205,7 @@ class Site extends BaseAdmin
$check_new_version_url = (!empty($_POST['check_new_version_url']) ? Strings::escapeTags(trim($_POST['check_new_version_url'])) : 'none');
$worker_queues = (!empty($_POST['worker_queues']) ? intval($_POST['worker_queues']) : 10);
$worker_dont_fork = !empty($_POST['worker_dont_fork']);
$worker_fastlane = !empty($_POST['worker_fastlane']);
$worker_frontend = !empty($_POST['worker_frontend']);
$relay_directly = !empty($_POST['relay_directly']);
$relay_server = (!empty($_POST['relay_server']) ? Strings::escapeTags(trim($_POST['relay_server'])) : '');
@ -417,13 +415,7 @@ class Site extends BaseAdmin
DI::config()->set('system', 'only_tag_search' , $only_tag_search);
DI::config()->set('system', 'worker_queues' , $worker_queues);
if (function_exists('proc_open')) {
DI::config()->set('system', 'worker_dont_fork', $worker_dont_fork);
}
DI::config()->set('system', 'worker_fastlane' , $worker_fastlane);
DI::config()->set('system', 'frontend_worker' , $worker_frontend);
DI::config()->set('system', 'relay_directly' , $relay_directly);
DI::config()->set('system', 'relay_server' , $relay_server);
@ -582,14 +574,6 @@ class Site extends BaseAdmin
}
}
if (function_exists('proc_open')) {
$worker_dont_fork = DI::config()->get('system', 'worker_dont_fork');
$worker_dont_fork_disabled = '';
} else {
$worker_dont_fork = true;
$worker_dont_fork_disabled = 'disabled';
}
$t = Renderer::getMarkupTemplate('admin/site.tpl');
return Renderer::replaceMacros($t, [
'$title' => DI::l10n()->t('Administration'),
@ -702,9 +686,7 @@ class Site extends BaseAdmin
'$rino' => ['rino', DI::l10n()->t('RINO Encryption'), intval(DI::config()->get('system', 'rino_encrypt')), DI::l10n()->t('Encryption layer between nodes.'), [0 => DI::l10n()->t('Disabled'), 1 => DI::l10n()->t('Enabled')]],
'$worker_queues' => ['worker_queues', DI::l10n()->t('Maximum number of parallel workers'), DI::config()->get('system', 'worker_queues'), DI::l10n()->t('On shared hosters set this to %d. On larger systems, values of %d are great. Default value is %d.', 5, 20, 10)],
'$worker_dont_fork' => ['worker_dont_fork', DI::l10n()->t('Don\'t use "proc_open" with the worker'), $worker_dont_fork, DI::l10n()->t('Enable this if your system doesn\'t allow the use of "proc_open". This can happen on shared hosters. If this is enabled you should increase the frequency of worker calls in your crontab.'), $worker_dont_fork_disabled],
'$worker_fastlane' => ['worker_fastlane', DI::l10n()->t('Enable fastlane'), DI::config()->get('system', 'worker_fastlane'), DI::l10n()->t('When enabed, the fastlane mechanism starts an additional worker if processes with higher priority are blocked by processes of lower priority.')],
'$worker_frontend' => ['worker_frontend', DI::l10n()->t('Enable frontend worker'), DI::config()->get('system', 'frontend_worker'), DI::l10n()->t('When enabled the Worker process is triggered when backend access is performed (e.g. messages being delivered). On smaller sites you might want to call %s/worker on a regular basis via an external cron job. You should only enable this option if you cannot utilize cron/scheduled jobs on your server.', DI::baseUrl()->get())],
'$relay_subscribe' => ['relay_subscribe', DI::l10n()->t('Use relay servers'), DI::config()->get('system', 'relay_subscribe'), DI::l10n()->t('Enables the receiving of public posts from relay servers. They will be included in the search, subscribed tags and on the global community page.')],
'$relay_server' => ['relay_server', DI::l10n()->t('"Social Relay" server'), DI::config()->get('system', 'relay_server'), DI::l10n()->t('Address of the "Social Relay" server where public posts should be send to. For example %s. ActivityRelay servers are administrated via the "console relay" command line command.', 'https://social-relay.isurf.ca')],

View file

@ -1,87 +0,0 @@
<?php
/**
* @copyright Copyright (C) 2020, Friendica
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\Process;
use Friendica\Core\System;
use Friendica\Core\Worker as WorkerCore;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Util\DateTimeFormat;
/**
* Module for starting the backend worker through a frontend call
*/
class Worker extends BaseModule
{
public static function rawContent(array $parameters = [])
{
if (!DI::config()->get("system", "frontend_worker")) {
return;
}
// Ensure that all "strtotime" operations do run timezone independent
date_default_timezone_set('UTC');
// We don't need the following lines if we can execute background jobs.
// So we just wake up the worker if it sleeps.
if (function_exists("proc_open")) {
WorkerCore::executeIfIdle();
return;
}
WorkerCore::clearProcesses();
$workers = DBA::count('process', ['command' => 'worker.php']);
if ($workers > DI::config()->get("system", "worker_queues", 4)) {
return;
}
DI::process()->start();
DI::logger()->notice('Front end worker started.', ['pid' => getmypid()]);
WorkerCore::callWorker();
if ($r = WorkerCore::workerProcess()) {
// On most configurations this parameter wouldn't have any effect.
// But since it doesn't destroy anything, we just try to get more execution time in any way.
set_time_limit(0);
$fields = ['executed' => DateTimeFormat::utcNow(), 'pid' => getmypid(), 'done' => false];
$condition = ['id' => $r[0]["id"], 'pid' => 0];
if (DBA::update('workerqueue', $fields, $condition)) {
WorkerCore::execute($r[0]);
}
}
WorkerCore::callWorker();
WorkerCore::unclaimProcess();
DI::process()->end();
System::httpExit(200, 'Frontend worker stopped.');
}
}