改名
This commit is contained in:
@@ -2,19 +2,55 @@
|
||||
|
||||
namespace Server\Worker;
|
||||
|
||||
use Exception;
|
||||
use Server\Constant;
|
||||
use Snowflake\Abstracts\Config;
|
||||
use Snowflake\Event;
|
||||
use Snowflake\Runtime;
|
||||
use Snowflake\Snowflake;
|
||||
use Swoole\Server;
|
||||
|
||||
class ServerWorker
|
||||
|
||||
/**
|
||||
* Class ServerWorker
|
||||
* @package Server\Worker
|
||||
*/
|
||||
class ServerWorker extends \Server\Abstracts\Server
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param Server $server
|
||||
* @param int $workerId
|
||||
* @throws Exception
|
||||
*/
|
||||
public function onWorkerStart(Server $server, int $workerId)
|
||||
{
|
||||
$annotation = Snowflake::app()->getAnnotation();
|
||||
$annotation->read(APP_PATH);
|
||||
$this->runEvent(Constant::WORKER_START, null, [$server, $workerId]);
|
||||
if ($workerId >= $server->setting['worker_num'] + 1) {
|
||||
$annotation->runtime(CONTROLLER_PATH);
|
||||
}
|
||||
Event::trigger(Event::SERVER_ON_WORKER_START, [$server, $workerId]);
|
||||
name($server->worker_pid, 'Worker.' . $workerId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $worker_id
|
||||
* @throws Exception
|
||||
*/
|
||||
private function setConfigs($worker_id)
|
||||
{
|
||||
putenv('state=start');
|
||||
putenv('worker=' . $worker_id);
|
||||
|
||||
$serialize = file_get_contents(storage(Runtime::CONFIG_NAME));
|
||||
if (empty($serialize)) {
|
||||
return;
|
||||
}
|
||||
Config::sets(unserialize($serialize));
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +60,7 @@ class ServerWorker
|
||||
*/
|
||||
public function onWorkerStop(Server $server, int $workerId)
|
||||
{
|
||||
|
||||
$this->runEvent(Constant::WORKER_STOP, null, [$server, $workerId]);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +70,7 @@ class ServerWorker
|
||||
*/
|
||||
public function onWorkerExit(Server $server, int $workerId)
|
||||
{
|
||||
|
||||
$this->runEvent(Constant::WORKER_EXIT, null, [$server, $workerId]);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +83,7 @@ class ServerWorker
|
||||
*/
|
||||
public function onWorkerError(Server $server, int $worker_id, int $worker_pid, int $exit_code, int $signal)
|
||||
{
|
||||
|
||||
$this->runEvent(Constant::WORKER_ERROR, null, [$server, $worker_id, $worker_pid, $exit_code, $signal]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user