This commit is contained in:
as2252258@163.com
2021-05-02 04:12:31 +08:00
parent cd4aad83de
commit 52f637ea25
3 changed files with 30 additions and 12 deletions
+17 -4
View File
@@ -9,6 +9,7 @@ use HttpServer\Abstracts\Callback;
use Snowflake\Event;
use Snowflake\Exception\ConfigException;
use Snowflake\Snowflake;
use Swoole\Coroutine;
use Swoole\Coroutine\System;
use Swoole\Server;
@@ -32,10 +33,7 @@ class OnWorkerStart extends Callback
putenv('state=start');
putenv('worker=' . $worker_id);
$content = System::readFile(storage('runtime.php'));
$annotation = Snowflake::app()->getAnnotation();
$annotation->setLoader(unserialize($content));
$annotation = $this->settings();
if ($worker_id < $server->setting['worker_num']) {
$this->onWorker($server, $annotation);
} else {
@@ -44,6 +42,21 @@ class OnWorkerStart extends Callback
}
/**
* @return \Annotation\Annotation
* @throws \Exception
*/
private function settings(): Annotation
{
$content = System::readFile(storage('runtime.php'));
$annotation = Snowflake::app()->getAnnotation();
$annotation->setLoader(unserialize($content));
return $annotation;
}
/**
* @param Server $server
* @param int $worker_id