47 lines
1009 B
PHP
47 lines
1009 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Console\Commands\Cluster;
|
||
|
|
||
|
use App\Support\ClusterSupport;
|
||
|
use Illuminate\Console\Command;
|
||
|
use Symfony\Component\Console\Command\Command as CommandAlias;
|
||
|
|
||
|
class Weight extends Command
|
||
|
{
|
||
|
/**
|
||
|
* The name and signature of the console command.
|
||
|
*
|
||
|
* @var string
|
||
|
*/
|
||
|
protected $signature = 'weight {weight=1}';
|
||
|
|
||
|
/**
|
||
|
* The console command description.
|
||
|
*
|
||
|
* @var string
|
||
|
*/
|
||
|
protected $description = '设置当前节点的权重。设置为 0 时,当前节点不参与负载均衡。';
|
||
|
|
||
|
/**
|
||
|
* Execute the console command.
|
||
|
*
|
||
|
* @return int
|
||
|
*/
|
||
|
public function handle(): int
|
||
|
{
|
||
|
$weight = $this->argument('weight');
|
||
|
|
||
|
$this->info("当前节点的权重为:{$weight}");
|
||
|
|
||
|
ClusterSupport::updateThisNode([
|
||
|
'weight' => $weight,
|
||
|
]);
|
||
|
|
||
|
ClusterSupport::publish('weight.updated', [
|
||
|
'weight' => $weight,
|
||
|
]);
|
||
|
|
||
|
return CommandAlias::SUCCESS;
|
||
|
}
|
||
|
}
|