From c5d7f26a8c22eef66ab25adade8513a8df5183fd Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 26 Dec 2024 19:04:27 +0000 Subject: [PATCH] Move code from worker.php into App::processWorker() --- bin/worker.php | 41 ++--------------------------------------- src/App.php | 41 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/bin/worker.php b/bin/worker.php index 684a5d8076..b88c30aeb5 100755 --- a/bin/worker.php +++ b/bin/worker.php @@ -15,12 +15,6 @@ if (php_sapi_name() !== 'cli') { } use Dice\Dice; -use Friendica\App\Mode; -use Friendica\Core\Logger\Capability\LogChannel; -use Friendica\Core\Update; -use Friendica\Core\Worker; -use Friendica\DI; -use Psr\Log\LoggerInterface; // Get options $options = getopt('sn', ['spawn', 'no_cron']); @@ -32,37 +26,6 @@ require dirname(__DIR__) . '/vendor/autoload.php'; $dice = (new Dice())->addRules(require(dirname(__DIR__) . '/static/dependencies.config.php')); -/** @var \Friendica\Core\Addon\Capability\ICanLoadAddons $addonLoader */ -$addonLoader = $dice->create(\Friendica\Core\Addon\Capability\ICanLoadAddons::class); -$dice = $dice->addRules($addonLoader->getActiveAddonConfig('dependencies')); -$dice = $dice->addRule(LoggerInterface::class, ['constructParams' => [LogChannel::WORKER]]); +$app = \Friendica\App::fromDice($dice); -DI::init($dice); -\Friendica\Core\Logger\Handler\ErrorHandler::register($dice->create(\Psr\Log\LoggerInterface::class)); - -DI::mode()->setExecutor(Mode::WORKER); - -// Check the database structure and possibly fixes it -Update::check(DI::basePath(), true); - -// Quit when in maintenance -if (!DI::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); - -$process = DI::process()->create(getmypid(), basename(__FILE__)); - -Worker::processQueue($run_cron, $process); - -Worker::unclaimProcess($process); - -DI::process()->delete($process); +$app->processWorker($options ?: []); diff --git a/src/App.php b/src/App.php index 0345eb3adf..fc42ca2b1a 100644 --- a/src/App.php +++ b/src/App.php @@ -47,8 +47,6 @@ use Friendica\Util\Profiler; use Psr\Http\Message\ServerRequestInterface; use Psr\Log\LoggerInterface; - - /** * Our main application structure for the life of this page. * @@ -436,6 +434,45 @@ class App } } + public function processWorker(array $options): void + { + /** @var \Friendica\Core\Addon\Capability\ICanLoadAddons $addonLoader */ + $addonLoader = $this->container->create(\Friendica\Core\Addon\Capability\ICanLoadAddons::class); + $this->container = $this->container->addRules($addonLoader->getActiveAddonConfig('dependencies')); + + $this->container = $this->container->addRule(LoggerInterface::class, ['constructParams' => [LogChannel::WORKER]]); + + DI::init($this->container); + \Friendica\Core\Logger\Handler\ErrorHandler::register($this->container->create(\Psr\Log\LoggerInterface::class)); + + DI::mode()->setExecutor(Mode::WORKER); + + // Check the database structure and possibly fixes it + Update::check(DI::basePath(), true); + + // Quit when in maintenance + if (!DI::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); + + $process = DI::process()->create(getmypid(), basename(__FILE__)); + + Worker::processQueue($run_cron, $process); + + Worker::unclaimProcess($process); + + DI::process()->delete($process); + } + private function setupContainerForAddons(): void { /** @var \Friendica\Core\Addon\Capability\ICanLoadAddons $addonLoader */