This commit is contained in:
2021-07-23 10:48:18 +08:00
parent 5bf0607460
commit 7ab08af442
2 changed files with 27 additions and 11 deletions
+20 -4
View File
@@ -2,6 +2,7 @@
namespace Server\Worker;
use Annotation\Annotation;
use Exception;
use Server\Constant;
use Snowflake\Abstracts\Config;
@@ -33,19 +34,34 @@ class ServerWorker extends \Server\Abstracts\Server
$annotation = Snowflake::app()->getAnnotation();
$annotation->read(APP_PATH . 'app');
debug(sprintf('Worker[%d]#%03d start.', $server->worker_pid, $workerId));
$this->runEvent(Constant::WORKER_START, null, [$server, $workerId]);
$this->workerInitExecutor($server, $annotation, $workerId);
}
/**
* @param Server $server
* @param Annotation $annotation
* @param int $workerId
* @throws ConfigException
* @throws Exception
*/
private function workerInitExecutor(Server $server, Annotation $annotation, int $workerId)
{
if ($workerId < $server->setting['worker_num']) {
$loader = Snowflake::app()->getRouter();
$loader->_loader();
$this->setProcessName(sprintf('Worker #%03d[%d]', $server->worker_pid, $workerId));
echo sprintf('Worker[%d].#%03d start.', $server->worker_pid, $workerId) . PHP_EOL;
$this->setProcessName(sprintf('Worker[%d].#%03d', $workerId, $server->worker_pid));
$annotation->runtime(CONTROLLER_PATH);
$annotation->runtime(MODEL_PATH);
} else {
$this->setProcessName(sprintf('Tasker #%03d[%d]', $server->worker_pid, $workerId));
echo sprintf('Tasker[%d].#%03d start.', $server->worker_pid, $workerId) . PHP_EOL;
$this->setProcessName(sprintf('Tasker[%d].#%03d', $workerId, $server->worker_pid));
$annotation->runtime(APP_PATH, [CONTROLLER_PATH]);
}
+7 -7
View File
@@ -886,7 +886,7 @@ if (!function_exists('swoole_substr_json_decode')) {
* @param int $length
* @return mixed
*/
function swoole_substr_json_decode($packet, $length = 0): mixed
function swoole_substr_json_decode($packet, int $length = 0): mixed
{
return json_decode($packet, true);
}
@@ -901,7 +901,7 @@ if (!function_exists('swoole_substr_unserialize')) {
* @param int $length
* @return mixed
*/
function swoole_substr_unserialize($packet, $length = 0): mixed
function swoole_substr_unserialize($packet, int $length = 0): mixed
{
return unserialize($packet);
}
@@ -912,7 +912,7 @@ if (!function_exists('swoole_substr_unserialize')) {
if (!function_exists('debug')) {
/**
* @param $message
* @param mixed $message
* @param string $method
* @throws Exception
*/
@@ -926,11 +926,11 @@ if (!function_exists('debug')) {
if (!function_exists('error')) {
/**
* @param $message
* @param mixed $message
* @param string $method
* @throws Exception
*/
function error(mixed $message, $method = 'error')
function error(mixed $message, string $method = 'error')
{
Snowflake::app()->error($message, $method);
}
@@ -939,11 +939,11 @@ if (!function_exists('error')) {
if (!function_exists('success')) {
/**
* @param $message
* @param mixed $message
* @param string $method
* @throws Exception
*/
function success(mixed $message, $method = 'app')
function success(mixed $message, string $method = 'app')
{
Snowflake::app()->success($message, $method);
}