mirror of
https://github.com/pelican-dev/panel.git
synced 2026-07-16 05:53:54 +03:00
Cleanup & fix server list (#1433)
This commit is contained in:
@@ -435,25 +435,24 @@ class Server extends Model implements Validatable
|
||||
|
||||
public function retrieveStatus(): ContainerStatus
|
||||
{
|
||||
$status = cache()->get("servers.$this->uuid.container.status");
|
||||
return cache()->remember("servers.$this->uuid.status", now()->addSeconds(15), function () {
|
||||
// @phpstan-ignore myCustomRules.forbiddenGlobalFunctions
|
||||
$details = app(DaemonServerRepository::class)->setServer($this)->getDetails();
|
||||
|
||||
if ($status === null) {
|
||||
$this->node->serverStatuses();
|
||||
|
||||
$status = cache()->get("servers.$this->uuid.container.status");
|
||||
}
|
||||
|
||||
return ContainerStatus::tryFrom($status) ?? ContainerStatus::Missing;
|
||||
return ContainerStatus::tryFrom(Arr::get($details, 'state')) ?? ContainerStatus::Missing;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function resources(): array
|
||||
public function retrieveResources(): array
|
||||
{
|
||||
return cache()->remember("resources:$this->uuid", now()->addSeconds(15), function () {
|
||||
return cache()->remember("servers.$this->uuid.resources", now()->addSeconds(15), function () {
|
||||
// @phpstan-ignore myCustomRules.forbiddenGlobalFunctions
|
||||
return Arr::get(app(DaemonServerRepository::class)->setServer($this)->getDetails(), 'utilization', []);
|
||||
$details = app(DaemonServerRepository::class)->setServer($this)->getDetails();
|
||||
|
||||
return Arr::get($details, 'utilization', []);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -461,7 +460,7 @@ class Server extends Model implements Validatable
|
||||
{
|
||||
$resourceAmount = $this->{$resourceKey} ?? 0;
|
||||
if (!$limit) {
|
||||
$resourceAmount = $this->resources()[$resourceKey] ?? 0;
|
||||
$resourceAmount = $this->retrieveResources()[$resourceKey] ?? 0;
|
||||
}
|
||||
|
||||
if ($type === ServerResourceType::Time) {
|
||||
@@ -494,7 +493,7 @@ class Server extends Model implements Validatable
|
||||
public function condition(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn () => $this->isSuspended() ? ServerState::Suspended : $this->status ?? $this->retrieveStatus(),
|
||||
get: fn () => $this->status ?? $this->retrieveStatus(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user