增加 清理心跳超时节点命令
This commit is contained in:
parent
786cb2b076
commit
126a18fac5
44
app/Console/Commands/Cluster/CleanOffline.php
Normal file
44
app/Console/Commands/Cluster/CleanOffline.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Cluster;
|
||||
|
||||
use App\Support\ClusterSupport;
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Command\Command as CommandAlias;
|
||||
|
||||
class CleanOffline extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'cluster:clean-offline';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '清理心跳超过 30 秒的节点。';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$nodes = ClusterSupport::nodes();
|
||||
|
||||
foreach ($nodes as $node) {
|
||||
$now = time();
|
||||
if ($now - $node['last_heartbeat'] > 30) {
|
||||
$this->info("节点 {$node['id']} 已离线,将被清理。");
|
||||
ClusterSupport::removeNode($node['id']);
|
||||
}
|
||||
}
|
||||
|
||||
return CommandAlias::SUCCESS;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user