-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAgentRegistryAndStateExample.php
More file actions
37 lines (29 loc) · 1.08 KB
/
Copy pathAgentRegistryAndStateExample.php
File metadata and controls
37 lines (29 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
declare(strict_types=1);
namespace imperazim\easylibrary\examples\agent;
use imperazim\agent\api\AgentRegistryAPI;
use imperazim\agent\api\AgentRuntimeAPI;
use imperazim\agent\api\AgentServerStateAPI;
final class AgentRegistryAndStateExample{
/** @return list<string> */
public function onlineServerIds() : array{
if(!AgentRuntimeAPI::isAvailable()){
return [];
}
$registry = AgentRegistryAPI::registry(50, false);
$ids = [];
foreach(($registry['servers'] ?? []) as $server){
if(is_array($server) && ($server['state'] ?? '') === 'online'){
$ids[] = (string) ($server['id'] ?? '');
}
}
return array_values(array_filter($ids, static fn(string $id) : bool => $id !== ''));
}
public function enableMaintenance(string $serverId, string $reason) : bool{
if(!AgentRuntimeAPI::isAvailable()){
return false;
}
$response = AgentServerStateAPI::maintenance($serverId, true, $reason);
return ($response['ok'] ?? false) === true;
}
}