Add managed registry provisioning, pruning, and readiness tracking
This commit is contained in:
@@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Application extends Model
|
||||
{
|
||||
@@ -15,6 +16,13 @@ class Application extends Model
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (Application $application): void {
|
||||
$application->uuid ??= (string) Str::uuid();
|
||||
});
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Environment extends Model
|
||||
{
|
||||
@@ -15,6 +16,13 @@ class Environment extends Model
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (Environment $environment): void {
|
||||
$environment->uuid ??= (string) Str::uuid();
|
||||
});
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -30,6 +30,7 @@ class Operation extends Model
|
||||
return [
|
||||
'kind' => OperationKind::class,
|
||||
'status' => OperationStatus::class,
|
||||
'metadata' => 'array',
|
||||
'started_at' => 'datetime',
|
||||
'finished_at' => 'datetime',
|
||||
];
|
||||
|
||||
@@ -13,6 +13,10 @@ class OperationStep extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
protected $hidden = [
|
||||
'secrets',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'logs_excerpt',
|
||||
'error_logs_excerpt',
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ class Server extends Model
|
||||
{
|
||||
return [
|
||||
'status' => ServerStatus::class,
|
||||
'is_control_node' => 'boolean',
|
||||
'build_enabled' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user