Add managed registry provisioning, pruning, and readiness tracking
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use App\Enums\RegistryType;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class Registry extends Model
|
||||
{
|
||||
@@ -17,6 +18,9 @@ class Registry extends Model
|
||||
return [
|
||||
'type' => RegistryType::class,
|
||||
'credentials' => 'encrypted:array',
|
||||
'readiness_checks' => 'array',
|
||||
'health_checked_at' => 'datetime',
|
||||
'ready_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -24,4 +28,34 @@ class Registry extends Model
|
||||
{
|
||||
return $this->belongsTo(Organisation::class);
|
||||
}
|
||||
|
||||
public function controlServer(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Server::class, 'control_server_id');
|
||||
}
|
||||
|
||||
public function markHealthy(?string $message = null): void
|
||||
{
|
||||
$this->forceFill([
|
||||
'health_status' => 'healthy',
|
||||
'health_message' => $message,
|
||||
'health_checked_at' => Carbon::now(),
|
||||
'ready_at' => $this->ready_at ?? Carbon::now(),
|
||||
])->save();
|
||||
}
|
||||
|
||||
public function markUnhealthy(string $message): void
|
||||
{
|
||||
$this->forceFill([
|
||||
'health_status' => 'unhealthy',
|
||||
'health_message' => $message,
|
||||
'health_checked_at' => Carbon::now(),
|
||||
'ready_at' => null,
|
||||
])->save();
|
||||
}
|
||||
|
||||
public function isReady(): bool
|
||||
{
|
||||
return $this->type !== RegistryType::MANAGED || ($this->ready_at !== null && $this->health_status === 'healthy');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user