mirror of
https://git.friendi.ca/friendica/friendica.git
synced 2025-06-07 20:04:32 +02:00
100 lines
2.4 KiB
PHP
100 lines
2.4 KiB
PHP
<?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);
|
|
}
|
|
}
|