This commit is contained in:
2021-03-09 19:40:10 +08:00
parent fa108ada6f
commit a456d95e66
4 changed files with 17 additions and 32 deletions
+5 -9
View File
@@ -26,15 +26,11 @@ class OnManagerStart extends Callback
*/
public function onHandler(Server $server)
{
// Snowflake::setWorkerId($server->manager_pid);
//
// $events = Snowflake::app()->getEvent();
// $events->trigger(Event::SERVER_MANAGER_START, [$server]);
//
// if (!Snowflake::getPlatform()->isLinux()) {
// return;
// }
// name(Config::get('id', false, 'system') . ' Server Manager.');
Snowflake::setWorkerId($server->manager_pid);
fire(Event::SERVER_MANAGER_START, [$server]);
name('Server Manager.');
}
+6 -17
View File
@@ -28,7 +28,6 @@ class OnWorkerStart extends Callback
* @param int $worker_id
*
* @return mixed
* @throws ConfigException
* @throws Exception
*/
public function onHandler(Server $server, int $worker_id): void
@@ -41,6 +40,8 @@ class OnWorkerStart extends Callback
$attribute->read(directory('app'), 'App');
}
$this->set_process_name($server, $worker_id);
if ($worker_id >= $server->setting['worker_num']) {
$this->onTask($server, $worker_id);
} else {
@@ -53,24 +54,20 @@ class OnWorkerStart extends Callback
* @param Server $server
* @param int $worker_id
* @throws ComponentException
* @throws ConfigException
* @throws Exception
*/
public function onTask(Server $server, int $worker_id)
{
putenv('environmental=' . Snowflake::TASK);
fire(Event::SERVER_TASK_START);
$this->set_process_name($server, $worker_id);
}
/**
* @param Server $server
* @param int $worker_id
* @param $prefix
* @throws ComponentException
* @throws ConfigException
* @throws Exception
*/
public function onWorker(Server $server, int $worker_id)
@@ -84,29 +81,21 @@ class OnWorkerStart extends Callback
$this->addError($exception);
write($exception->getMessage(), 'worker');
}
$this->set_process_name($server, $worker_id);
}
/**
* @param $socket
* @param $worker_id
* @return string
* @throws ConfigException
* @throws Exception
*/
private function set_process_name($socket, $worker_id): mixed
private function set_process_name($socket, $worker_id): void
{
$prefix = Config::get('id', false, 'system');
if ($worker_id >= $socket->setting['worker_num']) {
$name = $prefix . ' Task: No.' . $worker_id;
name('Task: No.' . $worker_id);
} else {
$name = $prefix . ' worker: No.' . $worker_id;
name('Worker: No.' . $worker_id);
}
if (Snowflake::getPlatform()->isMac()) {
return 1;
}
return swoole_set_process_name($name);
}
+2 -6
View File
@@ -46,16 +46,12 @@ class Kafka extends \Snowflake\Process\Process
/**
* @param array $kafkaServer
* @throws ComponentException
* @throws \Exception
*/
private function waite(array $kafkaServer)
{
try {
$prefix = rtrim(Snowflake::app()->id, ':');
if (!Snowflake::getPlatform()->isMac()) {
swoole_set_process_name($prefix . ' Kafka Consumer ' . $kafkaServer['topic']);
}
name('Kafka Consumer ' . $kafkaServer['topic']);
[$config, $topic, $conf] = $this->kafkaConfig($kafkaServer);
if (empty($config) && empty($topic) && empty($conf)) {
+4
View File
@@ -10,6 +10,7 @@ use HttpServer\Http\Request;
use HttpServer\Http\Response;
use HttpServer\Route\Router;
use JetBrains\PhpStorm\Pure;
use Snowflake\Abstracts\Config;
use Snowflake\Error\Logger;
use Snowflake\Exception\ComponentException;
use Snowflake\Exception\NotFindClassException;
@@ -566,6 +567,9 @@ if (!function_exists('name')) {
if (Snowflake::getPlatform()->isMac()) {
return;
}
$name = Config::get('id', false, 'system') .' '. $name;
swoole_set_process_name($name);
}