modify
This commit is contained in:
@@ -18,19 +18,6 @@ use Swoole\Server;
|
|||||||
class OnWorkerStart extends Callback
|
class OnWorkerStart extends Callback
|
||||||
{
|
{
|
||||||
|
|
||||||
private Server $server;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $server
|
|
||||||
* @param $worker_id
|
|
||||||
* @throws ConfigException
|
|
||||||
*/
|
|
||||||
public function actionBefore($server, $worker_id)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@@ -39,8 +26,13 @@ class OnWorkerStart extends Callback
|
|||||||
$runtime = file_get_contents(storage('runtime.php'));
|
$runtime = file_get_contents(storage('runtime.php'));
|
||||||
$annotation = Snowflake::app()->getAnnotation();
|
$annotation = Snowflake::app()->getAnnotation();
|
||||||
$annotation->setLoader(unserialize($runtime));
|
$annotation->setLoader(unserialize($runtime));
|
||||||
|
if ($isWorker) {
|
||||||
return $annotation;
|
$annotation->runtime(CONTROLLER_PATH);
|
||||||
|
$annotation->runtime(APP_PATH, CONTROLLER_PATH);
|
||||||
|
} else {
|
||||||
|
$annotation->runtime(MODEL_PATH);
|
||||||
|
}
|
||||||
|
return $isWorker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -53,30 +45,15 @@ class OnWorkerStart extends Callback
|
|||||||
*/
|
*/
|
||||||
public function onHandler(Server $server, int $worker_id): void
|
public function onHandler(Server $server, int $worker_id): void
|
||||||
{
|
{
|
||||||
(new Pipeline())
|
putenv('state=start');
|
||||||
->if($this->isWorker($worker_id), function ($handler, $server, $worker_id) {
|
putenv('worker=' . $worker_id);
|
||||||
$annotation = Snowflake::app()->getAnnotation();
|
|
||||||
$annotation->runtime(CONTROLLER_PATH);
|
|
||||||
$annotation->runtime(APP_PATH, CONTROLLER_PATH);
|
|
||||||
|
|
||||||
$handler->onWorker($server, $server->worker_id);
|
$isWorker = $this->isWorker($worker_id);
|
||||||
})
|
if ($this->injectLoader($isWorker)) {
|
||||||
->else(function ($handler, $server, $worker_id) {
|
$this->onWorker($server, $worker_id);
|
||||||
$annotation = Snowflake::app()->getAnnotation();
|
} else {
|
||||||
$annotation->runtime(MODEL_PATH);
|
$this->onTask($server);
|
||||||
|
}
|
||||||
$handler->onTask($server, $server->worker_id);
|
|
||||||
})
|
|
||||||
->catch(function (\Throwable $throwable) {
|
|
||||||
logger()->addError($throwable->getMessage());
|
|
||||||
})
|
|
||||||
->before(function ($annotation, $server, $worker_id) {
|
|
||||||
putenv('state=start');
|
|
||||||
putenv('worker=' . $worker_id);
|
|
||||||
|
|
||||||
$this->injectLoader();
|
|
||||||
})
|
|
||||||
->exec($this, $server, $worker_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -96,7 +73,7 @@ class OnWorkerStart extends Callback
|
|||||||
* @param int $worker_id
|
* @param int $worker_id
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function onTask(Server $server, int $worker_id)
|
public function onTask(Server $server)
|
||||||
{
|
{
|
||||||
putenv('environmental=' . Snowflake::TASK);
|
putenv('environmental=' . Snowflake::TASK);
|
||||||
|
|
||||||
@@ -111,13 +88,13 @@ class OnWorkerStart extends Callback
|
|||||||
* @param int $worker_id
|
* @param int $worker_id
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function onWorker(Server $server, int $worker_id)
|
public function onWorker(Server $server)
|
||||||
{
|
{
|
||||||
Snowflake::setWorkerId($server->worker_pid);
|
Snowflake::setWorkerId($server->worker_pid);
|
||||||
putenv('environmental=' . Snowflake::WORKER);
|
putenv('environmental=' . Snowflake::WORKER);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fire(Event::SERVER_WORKER_START, [$worker_id]);
|
fire(Event::SERVER_WORKER_START, [getenv('worker')]);
|
||||||
} catch (\Throwable $exception) {
|
} catch (\Throwable $exception) {
|
||||||
$this->addError($exception, 'throwable');
|
$this->addError($exception, 'throwable');
|
||||||
write($exception->getMessage(), 'worker');
|
write($exception->getMessage(), 'worker');
|
||||||
|
|||||||
Reference in New Issue
Block a user