增加 启动权重
This commit is contained in:
parent
51b7451de2
commit
342bd1d17d
@ -15,7 +15,7 @@ class Work extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'works';
|
||||
protected $signature = 'works {weight=1}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
@ -24,6 +24,8 @@ class Work extends Command
|
||||
*/
|
||||
protected $description = '启动此应用程序。';
|
||||
|
||||
private string $weight = "1";
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
@ -92,9 +94,13 @@ public function handle(): int
|
||||
$node_port = $node_ips[1];
|
||||
}
|
||||
|
||||
$this->weight = $this->argument('weight');
|
||||
|
||||
// redis 创建一个 hash
|
||||
$this->info('正在注册节点。');
|
||||
ClusterSupport::registerThisNode();
|
||||
ClusterSupport::registerThisNode(true, [
|
||||
'weight' => $this->weight,
|
||||
]);
|
||||
|
||||
$this->info('初始化完成。');
|
||||
|
||||
@ -115,6 +121,7 @@ public function handle(): int
|
||||
} else if ($pid === 0) {
|
||||
// 子进程
|
||||
$this->info('正在启动 Web。');
|
||||
$this->info('以权重 ' . $this->argument('weight') . ' 启动。');
|
||||
|
||||
$rpc_port = config('settings.node.rpc_port');
|
||||
|
||||
@ -189,7 +196,10 @@ private function work(): void
|
||||
{
|
||||
$this->info('正在监听任务。');
|
||||
|
||||
ClusterSupport::publish('node.online');
|
||||
ClusterSupport::publish('node.online', [
|
||||
'weight' => $this->weight,
|
||||
]);
|
||||
|
||||
ClusterSupport::listen('*', function ($event, $message) {
|
||||
$this->dispatchEvent($event, $message);
|
||||
}, false);
|
||||
|
Loading…
Reference in New Issue
Block a user