data = vCenter::select('id', 'host', 'user', 'password', 'token')->get(); $this->vCenter = new ServiceVCenter; $this->telegram = new Telegram(); } public function handle() { $resourcePoolCount = 0; foreach ($this->data as $item) { $token = $this->vCenter->loginServer($item); if (!$token) { continue; } $dataCenter = ModuleDatacenter::where('vcenter_id', $item->id) ->select('id', 'datacenter_id') ->get(); foreach ($dataCenter as $_item) { $allHost = ModuleHost::where('module_datacenter_id', $_item->id) ->select('id', 'name', 'host_id') ->get(); foreach ($allHost as $hostItem) { $resourcePool = $this->vCenter->getAllResourcePool($hostItem->host_id, $_item->datacenter_id); if ($resourcePool === 'Login_Again') { $token = $this->vCenter->loginServer($item); if ($token) { $resourcePool = $this->vCenter->getAllResourcePool($hostItem->host_id, $_item->datacenter_id); } else { continue; } } if (!is_array($resourcePool)) { continue; } foreach ($resourcePool as $_subItem) { ModuleResourcePool::updateOrCreate( [ 'resource_pool' => $_subItem['resource_pool'], 'module_host_id' => $hostItem->id, ], [ 'name' => $_subItem['name'], 'vcenter_id' => $item->id, 'status' => 1, ] ); $resourcePoolCount++; } } } } $this->telegram->SendJobRunInfo('SyncResourcePool', 'Success', [ 'message' => 'Sync resource pool completed successfully', 'synced_vcenters' => $this->data->count(), 'synced_resource_pool_count' => $resourcePoolCount, ]); } }