mirror of
https://github.com/friendica/friendica
synced 2025-01-06 20:44:42 +00:00
Move code from worker.php into App::processWorker()
This commit is contained in:
parent
bb9e09ef51
commit
c5d7f26a8c
2 changed files with 41 additions and 41 deletions
|
@ -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 ?: []);
|
||||
|
|
41
src/App.php
41
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 */
|
||||
|
|
Loading…
Reference in a new issue