This commit is contained in:
2021-04-09 10:28:01 +08:00
parent 8e2c4f51d8
commit 0db557e8fe
+10 -4
View File
@@ -9,6 +9,7 @@ use HttpServer\Abstracts\Callback;
use Snowflake\Event;
use Snowflake\Exception\ConfigException;
use Snowflake\Snowflake;
use Swoole\Coroutine\System;
use Swoole\Server;
/**
@@ -30,8 +31,12 @@ class OnWorkerStart extends Callback
putenv('state=start');
putenv('worker=' . $worker_id);
$open = fopen(storage('runtime.php'),'r');
$content = System::fread($open);
fclose($open);
$annotation = Snowflake::app()->getAnnotation();
$annotation->setLoader(unserialize(file_get_contents(storage('runtime.php'))));
$annotation->setLoader(unserialize($content));
if ($worker_id < $server->setting['worker_num']) {
$this->onWorker($server, $annotation);
@@ -46,7 +51,7 @@ class OnWorkerStart extends Callback
* @param int $worker_id
* @return bool
*/
private function isWorker($server, int $worker_id): bool
private function isWorker(Server $server, int $worker_id): bool
{
return $worker_id < $server->setting['worker_num'];
}
@@ -54,7 +59,8 @@ class OnWorkerStart extends Callback
/**
* @param Server $server
* @param int $worker_id
* @param Annotation $annotation
* @throws ConfigException
* @throws Exception
*/
public function onTask(Server $server, Annotation $annotation)
@@ -73,7 +79,7 @@ class OnWorkerStart extends Callback
/**
* @param Server $server
* @param int $worker_id
* @param Annotation $annotation
* @throws Exception
*/
public function onWorker(Server $server, Annotation $annotation)