Refactored WorkerSupervisor & subproc
This commit is contained in:
parent
13cade66cc
commit
21d0075ed5
2 changed files with 21 additions and 18 deletions
|
@ -11,7 +11,6 @@
|
||||||
use TamerLib\Objects\ServerConfiguration;
|
use TamerLib\Objects\ServerConfiguration;
|
||||||
use TamerLib\Objects\WorkerConfiguration;
|
use TamerLib\Objects\WorkerConfiguration;
|
||||||
use TamerLib\Objects\WorkerInstance;
|
use TamerLib\Objects\WorkerInstance;
|
||||||
use TamerLib\tm;
|
|
||||||
|
|
||||||
class WorkerSupervisor
|
class WorkerSupervisor
|
||||||
{
|
{
|
||||||
|
@ -37,8 +36,8 @@
|
||||||
/**
|
/**
|
||||||
* Generates a worker configuration object.
|
* Generates a worker configuration object.
|
||||||
*
|
*
|
||||||
* @param int $channel
|
* @param int $channel The channel to use for the worker.
|
||||||
* @return WorkerConfiguration
|
* @return WorkerConfiguration The generated worker configuration.
|
||||||
*/
|
*/
|
||||||
private function generateWorkerConfiguration(int $channel=0): WorkerConfiguration
|
private function generateWorkerConfiguration(int $channel=0): WorkerConfiguration
|
||||||
{
|
{
|
||||||
|
@ -55,12 +54,12 @@
|
||||||
/**
|
/**
|
||||||
* Spawns a specified number of workers for a given path.
|
* Spawns a specified number of workers for a given path.
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path Optional. The path to the worker file, defaults to subproc.
|
||||||
* @param int $count
|
* @param int $count Optional. The number of workers to spawn, defaults to 8.
|
||||||
* @param int $channel
|
* @param int $channel Optional. The channel to use for the workers, defaults to 0.
|
||||||
* @param bool $check
|
* @param bool $check Optional. Whether to check if the workers have started, defaults to true.
|
||||||
|
* @throws WorkerFailedException Thrown if the worker fails to start.
|
||||||
* @return void
|
* @return void
|
||||||
* @throws WorkerFailedException
|
|
||||||
*/
|
*/
|
||||||
public function spawnWorker(string $path, int $count=8, int $channel=0, bool $check=true): void
|
public function spawnWorker(string $path, int $count=8, int $channel=0, bool $check=true): void
|
||||||
{
|
{
|
||||||
|
@ -70,7 +69,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::verbose(Utilities::getName(), sprintf('Spawning %s workers for %s', $count, $path));
|
Log::verbose(Utilities::getName(), sprintf('Spawning %s workers for %s', $count, $path));
|
||||||
|
|
||||||
$spawned_workers = [];
|
$spawned_workers = [];
|
||||||
|
|
||||||
for($i = 0; $i < $count; $i++)
|
for($i = 0; $i < $count; $i++)
|
||||||
|
@ -91,9 +89,9 @@
|
||||||
/**
|
/**
|
||||||
* Checks if the workers have started.
|
* Checks if the workers have started.
|
||||||
*
|
*
|
||||||
* @param array $workers
|
* @param array $workers The workers to check.
|
||||||
|
* @throws WorkerFailedException Thrown if the worker fails to start.
|
||||||
* @return void
|
* @return void
|
||||||
* @throws WorkerFailedException
|
|
||||||
*/
|
*/
|
||||||
private function checkWorkers(array $workers): void
|
private function checkWorkers(array $workers): void
|
||||||
{
|
{
|
||||||
|
@ -125,10 +123,10 @@
|
||||||
/**
|
/**
|
||||||
* Spawns a closure as a worker process. (built-in worker)
|
* Spawns a closure as a worker process. (built-in worker)
|
||||||
*
|
*
|
||||||
* @param int $count
|
* @param int $count The number of workers to spawn.
|
||||||
* @param int $channel
|
* @param int $channel The channel to use for the workers.
|
||||||
|
* @throws WorkerFailedException Thrown if the worker fails to start.
|
||||||
* @return void
|
* @return void
|
||||||
* @throws WorkerFailedException
|
|
||||||
*/
|
*/
|
||||||
public function spawnClosure(int $count=8, int $channel=0): void
|
public function spawnClosure(int $count=8, int $channel=0): void
|
||||||
{
|
{
|
||||||
|
@ -145,6 +143,11 @@
|
||||||
*/
|
*/
|
||||||
public function printUpdates(): void
|
public function printUpdates(): void
|
||||||
{
|
{
|
||||||
|
if(count($this->workers) === 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/** @var WorkerInstance $worker */
|
/** @var WorkerInstance $worker */
|
||||||
foreach($this->workers as $worker)
|
foreach($this->workers as $worker)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<?PHP /** @noinspection PhpFullyQualifiedNameUsageInspection */
|
<?PHP
|
||||||
/** @noinspection PhpFullyQualifiedNameUsageInspection */
|
|
||||||
/** @noinspection PhpFullyQualifiedNameUsageInspection */
|
|
||||||
|
|
||||||
require 'ncc';
|
/** @noinspection PhpFullyQualifiedNameUsageInspection */
|
||||||
|
|
||||||
|
require 'ncc';
|
||||||
import('net.nosial.tamerlib');
|
import('net.nosial.tamerlib');
|
||||||
|
|
||||||
\TamerLib\tm::initialize(\TamerLib\Enums\TamerMode::WORKER);
|
\TamerLib\tm::initialize(\TamerLib\Enums\TamerMode::WORKER);
|
||||||
|
|
Loading…
Add table
Reference in a new issue