增加 启动权重
This commit is contained in:
parent
51b7451de2
commit
342bd1d17d
@ -15,7 +15,7 @@ class Work extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'works';
|
protected $signature = 'works {weight=1}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
@ -24,6 +24,8 @@ class Work extends Command
|
|||||||
*/
|
*/
|
||||||
protected $description = '启动此应用程序。';
|
protected $description = '启动此应用程序。';
|
||||||
|
|
||||||
|
private string $weight = "1";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
*
|
*
|
||||||
@ -32,7 +34,7 @@ class Work extends Command
|
|||||||
public function handle(): int
|
public function handle(): int
|
||||||
{
|
{
|
||||||
// 检测目录下是否有 rr
|
// 检测目录下是否有 rr
|
||||||
if (! file_exists(base_path('rr'))) {
|
if (!file_exists(base_path('rr'))) {
|
||||||
$this->warn('未找到 rr 文件,将自动下载。');
|
$this->warn('未找到 rr 文件,将自动下载。');
|
||||||
|
|
||||||
// 获取操作系统是 darwin 还是 linux
|
// 获取操作系统是 darwin 还是 linux
|
||||||
@ -77,7 +79,7 @@ public function handle(): int
|
|||||||
|
|
||||||
$node_ip = config('settings.node.ip');
|
$node_ip = config('settings.node.ip');
|
||||||
|
|
||||||
if (! $node_ip) {
|
if (!$node_ip) {
|
||||||
$this->error('请先配置节点 IP。');
|
$this->error('请先配置节点 IP。');
|
||||||
|
|
||||||
return CommandAlias::FAILURE;
|
return CommandAlias::FAILURE;
|
||||||
@ -92,9 +94,13 @@ public function handle(): int
|
|||||||
$node_port = $node_ips[1];
|
$node_port = $node_ips[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->weight = $this->argument('weight');
|
||||||
|
|
||||||
// redis 创建一个 hash
|
// redis 创建一个 hash
|
||||||
$this->info('正在注册节点。');
|
$this->info('正在注册节点。');
|
||||||
ClusterSupport::registerThisNode();
|
ClusterSupport::registerThisNode(true, [
|
||||||
|
'weight' => $this->weight,
|
||||||
|
]);
|
||||||
|
|
||||||
$this->info('初始化完成。');
|
$this->info('初始化完成。');
|
||||||
|
|
||||||
@ -105,16 +111,17 @@ public function handle(): int
|
|||||||
$this->error('无法创建子进程。');
|
$this->error('无法创建子进程。');
|
||||||
|
|
||||||
return CommandAlias::FAILURE;
|
return CommandAlias::FAILURE;
|
||||||
} elseif ($pid === 0) {
|
} else if ($pid === 0) {
|
||||||
// 再打开一个,负责 octane
|
// 再打开一个,负责 octane
|
||||||
$pid = pcntl_fork();
|
$pid = pcntl_fork();
|
||||||
if ($pid === -1) {
|
if ($pid === -1) {
|
||||||
$this->error('无法创建子进程。');
|
$this->error('无法创建子进程。');
|
||||||
|
|
||||||
return CommandAlias::FAILURE;
|
return CommandAlias::FAILURE;
|
||||||
} elseif ($pid === 0) {
|
} else if ($pid === 0) {
|
||||||
// 子进程
|
// 子进程
|
||||||
$this->info('正在启动 Web。');
|
$this->info('正在启动 Web。');
|
||||||
|
$this->info('以权重 ' . $this->argument('weight') . ' 启动。');
|
||||||
|
|
||||||
$rpc_port = config('settings.node.rpc_port');
|
$rpc_port = config('settings.node.rpc_port');
|
||||||
|
|
||||||
@ -189,7 +196,10 @@ private function work(): void
|
|||||||
{
|
{
|
||||||
$this->info('正在监听任务。');
|
$this->info('正在监听任务。');
|
||||||
|
|
||||||
ClusterSupport::publish('node.online');
|
ClusterSupport::publish('node.online', [
|
||||||
|
'weight' => $this->weight,
|
||||||
|
]);
|
||||||
|
|
||||||
ClusterSupport::listen('*', function ($event, $message) {
|
ClusterSupport::listen('*', function ($event, $message) {
|
||||||
$this->dispatchEvent($event, $message);
|
$this->dispatchEvent($event, $message);
|
||||||
}, false);
|
}, false);
|
||||||
|
Loading…
Reference in New Issue
Block a user