SyncHysteria2Data.php 960 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Jobs\Hysteria2\GetOnlineUser;
  4. use App\Jobs\Hysteria2\GetTrafficStats;
  5. use App\Models\Node;
  6. use Illuminate\Console\Command;
  7. use Log;
  8. class SyncHysteria2Data extends Command
  9. {
  10. protected $signature = 'hysteria2:sync';
  11. protected $description = '同步Hysteria2节点流量数据';
  12. public function handle(): void
  13. {
  14. $jobTime = microtime(true);
  15. $this->info('开始同步Hysteria2节点流量数据');
  16. // 同步所有Hysteria2节点
  17. $hysteria2Nodes = Node::where('type', 5)->where('status', 1)->get();
  18. if ($hysteria2Nodes->isNotEmpty()) {
  19. GetTrafficStats::dispatchSync($hysteria2Nodes);
  20. GetOnlineUser::dispatchSync($hysteria2Nodes);
  21. }
  22. $jobTime = round(microtime(true) - $jobTime, 4);
  23. Log::info(__('----「:job」Completed, Used :time seconds ----', ['job' => $this->description, 'time' => $jobTime]));
  24. }
  25. }