* 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') {
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__));
$app = \Friendica\App::fromDice($dice);
-$app->processWorker($options ?: []);
+$argv = $_SERVER['argv'] ?? [];
+array_splice($argv, 1, 0, "worker");
+
+$app->processConsole($argv);
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;
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;
(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 */
--- /dev/null
+<?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);
+ }
+}
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)
'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,