增加 权重设置
This commit is contained in:
parent
342bd1d17d
commit
118e5e0550
46
app/Console/Commands/Cluster/Weight.php
Normal file
46
app/Console/Commands/Cluster/Weight.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user