mirror of
https://github.com/friendica/friendica
synced 2025-02-10 19:34:01 +00:00
Move 'bin/worker.php' to 'bin/console.php worker'
This commit is contained in:
parent
07c4e606e1
commit
c58cd835d2
4 changed files with 108 additions and 55 deletions
|
@ -7,6 +7,8 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
*
|
*
|
||||||
* Starts the background processing
|
* Starts the background processing
|
||||||
|
*
|
||||||
|
* @deprecated 2025.01 use bin/console.php worker instead
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (php_sapi_name() !== 'cli') {
|
if (php_sapi_name() !== 'cli') {
|
||||||
|
@ -16,9 +18,6 @@ if (php_sapi_name() !== 'cli') {
|
||||||
|
|
||||||
use Dice\Dice;
|
use Dice\Dice;
|
||||||
|
|
||||||
// Get options
|
|
||||||
$options = getopt('sn', ['spawn', 'no_cron']);
|
|
||||||
|
|
||||||
// Ensure that worker.php is executed from the base path of the installation
|
// Ensure that worker.php is executed from the base path of the installation
|
||||||
chdir(dirname(__DIR__));
|
chdir(dirname(__DIR__));
|
||||||
|
|
||||||
|
@ -28,4 +27,7 @@ $dice = (new Dice())->addRules(require(dirname(__DIR__) . '/static/dependencies.
|
||||||
|
|
||||||
$app = \Friendica\App::fromDice($dice);
|
$app = \Friendica\App::fromDice($dice);
|
||||||
|
|
||||||
$app->processWorker($options ?: []);
|
$argv = $_SERVER['argv'] ?? [];
|
||||||
|
array_splice($argv, 1, 0, "worker");
|
||||||
|
|
||||||
|
$app->processConsole($argv);
|
||||||
|
|
51
src/App.php
51
src/App.php
|
@ -20,7 +20,6 @@ use Friendica\Content\Nav;
|
||||||
use Friendica\Core\Config\Factory\Config;
|
use Friendica\Core\Config\Factory\Config;
|
||||||
use Friendica\Core\Renderer;
|
use Friendica\Core\Renderer;
|
||||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||||
use Friendica\Core\Worker\Repository\Process as ProcessRepository;
|
|
||||||
use Friendica\Database\Definition\DbaDefinition;
|
use Friendica\Database\Definition\DbaDefinition;
|
||||||
use Friendica\Database\Definition\ViewDefinition;
|
use Friendica\Database\Definition\ViewDefinition;
|
||||||
use Friendica\Module\Maintenance;
|
use Friendica\Module\Maintenance;
|
||||||
|
@ -31,7 +30,6 @@ use Friendica\Core\Logger\Capability\LogChannel;
|
||||||
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
|
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Core\Update;
|
use Friendica\Core\Update;
|
||||||
use Friendica\Core\Worker;
|
|
||||||
use Friendica\Module\Special\HTTPException as ModuleHTTPException;
|
use Friendica\Module\Special\HTTPException as ModuleHTTPException;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Protocol\ATProtocol\DID;
|
use Friendica\Protocol\ATProtocol\DID;
|
||||||
|
@ -215,55 +213,6 @@ class App
|
||||||
(new \Friendica\Core\Console($this->container, $argv))->execute();
|
(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
|
private function setupContainerForAddons(): void
|
||||||
{
|
{
|
||||||
/** @var \Friendica\Core\Addon\Capability\ICanLoadAddons $addonLoader */
|
/** @var \Friendica\Core\Addon\Capability\ICanLoadAddons $addonLoader */
|
||||||
|
|
100
src/Console/Worker.php
Normal file
100
src/Console/Worker.php
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// Copyright (C) 2010-2024, the Friendica project
|
||||||
|
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Friendica\Console;
|
||||||
|
|
||||||
|
use Friendica\App\Mode;
|
||||||
|
use Asika\SimpleConsole\Console;
|
||||||
|
use Friendica\Core\Update;
|
||||||
|
use Friendica\Core\Worker as CoreWorker;
|
||||||
|
use Friendica\Core\Worker\Repository\Process as ProcessRepository;
|
||||||
|
use Friendica\Util\BasePath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Console command for interacting with the daemon
|
||||||
|
*/
|
||||||
|
final class Worker extends Console
|
||||||
|
{
|
||||||
|
private Mode $mode;
|
||||||
|
private BasePath $basePath;
|
||||||
|
private ProcessRepository $processRepo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Mode $mode
|
||||||
|
* @param BasePath $basePath
|
||||||
|
* @param ProcessRepository $processRepo
|
||||||
|
* @param array|null $argv
|
||||||
|
*/
|
||||||
|
public function __construct(Mode $mode, BasePath $basePath, ProcessRepository $processRepo, array $argv = null)
|
||||||
|
{
|
||||||
|
parent::__construct($argv);
|
||||||
|
|
||||||
|
$this->mode = $mode;
|
||||||
|
$this->basePath = $basePath;
|
||||||
|
$this->processRepo = $processRepo;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getHelp(): string
|
||||||
|
{
|
||||||
|
return <<<HELP
|
||||||
|
Worker - Start a worker
|
||||||
|
Synopsis
|
||||||
|
bin/console worker [-h|--help|-?] [-v] [-n|--no_cron] [-s|--spawn]
|
||||||
|
|
||||||
|
Description
|
||||||
|
Start a worker process
|
||||||
|
|
||||||
|
Options
|
||||||
|
-h|--help|-? Show help information
|
||||||
|
-v Show more debug information.
|
||||||
|
-n|--no_cron Don't executes the Cronjob
|
||||||
|
-s|--spawn Spawn an additional worker
|
||||||
|
|
||||||
|
Examples
|
||||||
|
bin/console daemon start -f
|
||||||
|
Starts the daemon in the foreground
|
||||||
|
|
||||||
|
bin/console daemon status
|
||||||
|
Gets the status of the daemon
|
||||||
|
HELP;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function doExecute()
|
||||||
|
{
|
||||||
|
if ($this->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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -39,6 +39,7 @@ Commands:
|
||||||
createdoxygen Generate Doxygen headers
|
createdoxygen Generate Doxygen headers
|
||||||
daemon Interact with the Friendica daemon
|
daemon Interact with the Friendica daemon
|
||||||
jetstream Interact with the Jetstream daemon
|
jetstream Interact with the Jetstream daemon
|
||||||
|
worker Start worker process
|
||||||
dbstructure Do database updates
|
dbstructure Do database updates
|
||||||
docbloxerrorchecker Check the file tree for DocBlox errors
|
docbloxerrorchecker Check the file tree for DocBlox errors
|
||||||
extract Generate translation string file for the Friendica project (deprecated)
|
extract Generate translation string file for the Friendica project (deprecated)
|
||||||
|
@ -79,6 +80,7 @@ HELP;
|
||||||
'createdoxygen' => Friendica\Console\CreateDoxygen::class,
|
'createdoxygen' => Friendica\Console\CreateDoxygen::class,
|
||||||
'daemon' => Friendica\Console\Daemon::class,
|
'daemon' => Friendica\Console\Daemon::class,
|
||||||
'jetstream' => Friendica\Console\JetstreamDaemon::class,
|
'jetstream' => Friendica\Console\JetstreamDaemon::class,
|
||||||
|
'worker' => Friendica\Console\Worker::class,
|
||||||
'docbloxerrorchecker' => Friendica\Console\DocBloxErrorChecker::class,
|
'docbloxerrorchecker' => Friendica\Console\DocBloxErrorChecker::class,
|
||||||
'dbstructure' => Friendica\Console\DatabaseStructure::class,
|
'dbstructure' => Friendica\Console\DatabaseStructure::class,
|
||||||
'extract' => Friendica\Console\Extract::class,
|
'extract' => Friendica\Console\Extract::class,
|
||||||
|
|
Loading…
Add table
Reference in a new issue