qqq
This commit is contained in:
@@ -17,6 +17,7 @@ use Psr\Container\ContainerExceptionInterface;
|
|||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
use Swoole\Server;
|
use Swoole\Server;
|
||||||
|
use Swoole\Timer;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,8 +43,12 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server
|
|||||||
set_env('environmental_workerId', $workerId);
|
set_env('environmental_workerId', $workerId);
|
||||||
|
|
||||||
if ($workerId < $server->setting['worker_num']) {
|
if ($workerId < $server->setting['worker_num']) {
|
||||||
|
$this->processName($server, 'Worker');
|
||||||
|
set_env('environmental', Kiri::WORKER);
|
||||||
$dispatch->dispatch(new OnWorkerStart($server, $workerId));
|
$dispatch->dispatch(new OnWorkerStart($server, $workerId));
|
||||||
} else {
|
} else {
|
||||||
|
$this->processName($server, 'Tasker');
|
||||||
|
set_env('environmental', Kiri::TASK);;
|
||||||
$dispatch->dispatch(new OnTaskStart($server, $workerId));
|
$dispatch->dispatch(new OnTaskStart($server, $workerId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,6 +56,18 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Server $server
|
||||||
|
* @param string $prefix
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function processName(Server $server, string $prefix): void
|
||||||
|
{
|
||||||
|
$prefix = sprintf($prefix . ' Process[%d].%d', $server->worker_pid, $server->worker_id);
|
||||||
|
Kiri::setProcessName($prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Server $server
|
* @param Server $server
|
||||||
* @param int $workerId
|
* @param int $workerId
|
||||||
@@ -60,6 +77,7 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server
|
|||||||
public function onWorkerStop(Server $server, int $workerId): void
|
public function onWorkerStop(Server $server, int $workerId): void
|
||||||
{
|
{
|
||||||
event(new OnWorkerStop($server, $workerId));
|
event(new OnWorkerStop($server, $workerId));
|
||||||
|
Timer::clearAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
-45
@@ -8,13 +8,9 @@ use Kiri;
|
|||||||
use Kiri\Events\EventDispatch;
|
use Kiri\Events\EventDispatch;
|
||||||
use Kiri\Router\Router;
|
use Kiri\Router\Router;
|
||||||
use Kiri\Server\Events\OnShutdown;
|
use Kiri\Server\Events\OnShutdown;
|
||||||
use Kiri\Server\Events\OnTaskerStart;
|
|
||||||
use Kiri\Server\Events\OnWorkerStart;
|
|
||||||
use Kiri\Server\Events\OnWorkerStop;
|
|
||||||
use Kiri\Server\Abstracts\AsyncServer;
|
use Kiri\Server\Abstracts\AsyncServer;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
use Swoole\Timer;
|
|
||||||
|
|
||||||
|
|
||||||
defined('PID_PATH') or define('PID_PATH', APP_PATH . 'storage/server.pid');
|
defined('PID_PATH') or define('PID_PATH', APP_PATH . 'storage/server.pid');
|
||||||
@@ -48,23 +44,12 @@ class Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function init(): void
|
|
||||||
{
|
|
||||||
on(OnWorkerStart::class, [$this, 'onWorkerName']);
|
|
||||||
on(OnTaskerStart::class, [$this, 'onTaskerName']);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function start(): void
|
public function start(): void
|
||||||
{
|
{
|
||||||
on(OnWorkerStop::class, [Timer::class, 'clearAll'], 9999);
|
|
||||||
if (\config('reload.hot', false) === true) {
|
if (\config('reload.hot', false) === true) {
|
||||||
$this->manager->addProcess(HotReload::class);
|
$this->manager->addProcess(HotReload::class);
|
||||||
} else {
|
} else {
|
||||||
@@ -75,36 +60,6 @@ class Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param OnWorkerStart $onWorkerStart
|
|
||||||
*/
|
|
||||||
public function onWorkerName(OnWorkerStart $onWorkerStart): void
|
|
||||||
{
|
|
||||||
if (!property_exists($onWorkerStart->server, 'worker_pid')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$prefix = sprintf('Worker Process[%d].%d', $onWorkerStart->server->worker_pid, $onWorkerStart->workerId);
|
|
||||||
set_env('environmental', Kiri::WORKER);
|
|
||||||
|
|
||||||
Kiri::setProcessName($prefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param OnTaskerStart $onWorkerStart
|
|
||||||
*/
|
|
||||||
public function onTaskerName(OnTaskerStart $onWorkerStart): void
|
|
||||||
{
|
|
||||||
if (!property_exists($onWorkerStart->server, 'worker_pid')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$prefix = sprintf('Tasker Process[%d].%d', $onWorkerStart->server->worker_pid, $onWorkerStart->workerId);
|
|
||||||
set_env('environmental', Kiri::TASK);
|
|
||||||
|
|
||||||
Kiri::setProcessName($prefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
* @throws ContainerExceptionInterface
|
* @throws ContainerExceptionInterface
|
||||||
|
|||||||
Reference in New Issue
Block a user