diff --git a/bin/worker.php b/bin/worker.php index b88c30aeb5..4837cd67eb 100755 --- a/bin/worker.php +++ b/bin/worker.php @@ -7,6 +7,8 @@ * SPDX-License-Identifier: AGPL-3.0-or-later * * Starts the background processing + * + * @deprecated 2025.01 use bin/console.php worker instead */ if (php_sapi_name() !== 'cli') { @@ -16,9 +18,6 @@ if (php_sapi_name() !== 'cli') { use Dice\Dice; -// Get options -$options = getopt('sn', ['spawn', 'no_cron']); - // Ensure that worker.php is executed from the base path of the installation chdir(dirname(__DIR__)); @@ -28,4 +27,7 @@ $dice = (new Dice())->addRules(require(dirname(__DIR__) . '/static/dependencies. $app = \Friendica\App::fromDice($dice); -$app->processWorker($options ?: []); +$argv = $_SERVER['argv'] ?? []; +array_splice($argv, 1, 0, "worker"); + +$app->processConsole($argv); diff --git a/src/App.php b/src/App.php index 923400a21c..7998152665 100644 --- a/src/App.php +++ b/src/App.php @@ -20,7 +20,6 @@ use Friendica\Content\Nav; use Friendica\Core\Config\Factory\Config; use Friendica\Core\Renderer; use Friendica\Core\Session\Capability\IHandleUserSessions; -use Friendica\Core\Worker\Repository\Process as ProcessRepository; use Friendica\Database\Definition\DbaDefinition; use Friendica\Database\Definition\ViewDefinition; use Friendica\Module\Maintenance; @@ -31,7 +30,6 @@ use Friendica\Core\Logger\Capability\LogChannel; use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; use Friendica\Core\System; use Friendica\Core\Update; -use Friendica\Core\Worker; use Friendica\Module\Special\HTTPException as ModuleHTTPException; use Friendica\Network\HTTPException; use Friendica\Protocol\ATProtocol\DID; @@ -215,55 +213,6 @@ class App (new \Friendica\Core\Console($this->container, $argv))->execute(); } - public function processWorker(array $options): void - { - $this->setupContainerForAddons(); - - $this->setupContainerForLogger(LogChannel::WORKER); - - $this->setupLegacyServiceLocator(); - - $this->registerErrorHandler(); - - $this->registerTemplateEngine(); - - /** @var Mode */ - $mode = $this->container->create(Mode::class); - - $mode->setExecutor(Mode::WORKER); - - /** @var BasePath */ - $basePath = $this->container->create(BasePath::class); - - // Check the database structure and possibly fixes it - Update::check($basePath->getPath(), true); - - // Quit when in maintenance - if (!$mode->has(Mode::MAINTENANCEDISABLED)) { - return; - } - - $spawn = array_key_exists('s', $options) || array_key_exists('spawn', $options); - - if ($spawn) { - Worker::spawnWorker(); - exit(); - } - - $run_cron = !array_key_exists('n', $options) && !array_key_exists('no_cron', $options); - - /** @var ProcessRepository */ - $processRepository = $this->container->create(ProcessRepository::class); - - $process = $processRepository->create(getmypid(), 'worker.php'); - - Worker::processQueue($run_cron, $process); - - Worker::unclaimProcess($process); - - $processRepository->delete($process); - } - private function setupContainerForAddons(): void { /** @var \Friendica\Core\Addon\Capability\ICanLoadAddons $addonLoader */ diff --git a/src/Console/Worker.php b/src/Console/Worker.php new file mode 100644 index 0000000000..fa15b2e414 --- /dev/null +++ b/src/Console/Worker.php @@ -0,0 +1,100 @@ +mode = $mode; + $this->basePath = $basePath; + $this->processRepo = $processRepo; + } + + protected function getHelp(): string + { + return <<executable !== 'bin/console.php') { + $this->out(sprintf("'%s' is deprecated and will removed. Please use 'bin/console.php worker' instead", $this->executable)); + } + + $this->mode->setExecutor(Mode::WORKER); + + // Check the database structure and possibly fixes it + Update::check($this->basePath->getPath(), true); + + // Quit when in maintenance + if (!$this->mode->has(Mode::MAINTENANCEDISABLED)) { + return; + } + + $spawn = $this->getOption(['s', 'spawn'], false); + + if ($spawn) { + CoreWorker::spawnWorker(); + exit(); + } + + $run_cron = !$this->getOption(['n', 'no_cron'], false); + + $process = $this->processRepo->create(getmypid(), 'worker.php'); + + CoreWorker::processQueue($run_cron, $process); + CoreWorker::unclaimProcess($process); + + $this->processRepo->delete($process); + } +} diff --git a/src/Core/Console.php b/src/Core/Console.php index 6865a4d25a..e371882465 100644 --- a/src/Core/Console.php +++ b/src/Core/Console.php @@ -39,6 +39,7 @@ Commands: createdoxygen Generate Doxygen headers daemon Interact with the Friendica daemon jetstream Interact with the Jetstream daemon + worker Start worker process dbstructure Do database updates docbloxerrorchecker Check the file tree for DocBlox errors extract Generate translation string file for the Friendica project (deprecated) @@ -79,6 +80,7 @@ HELP; 'createdoxygen' => Friendica\Console\CreateDoxygen::class, 'daemon' => Friendica\Console\Daemon::class, 'jetstream' => Friendica\Console\JetstreamDaemon::class, + 'worker' => Friendica\Console\Worker::class, 'docbloxerrorchecker' => Friendica\Console\DocBloxErrorChecker::class, 'dbstructure' => Friendica\Console\DatabaseStructure::class, 'extract' => Friendica\Console\Extract::class,