VPS and dedicated server ordering, managed panels, SSO, billing, and launcher integration — forked from hosting infrastructure with server-focused routes and dashboard. Co-authored-by: Cursor <cursoragent@cursor.com>
99 lines
2.8 KiB
PHP
99 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class ServerTask extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
public const STATUS_QUEUED = 'queued';
|
|
public const STATUS_DISPATCHED = 'dispatched';
|
|
public const STATUS_RUNNING = 'running';
|
|
public const STATUS_COMPLETED = 'completed';
|
|
public const STATUS_FAILED = 'failed';
|
|
|
|
public const TYPE_DOMAIN_ADD = 'domain.add';
|
|
public const TYPE_SSL_REQUEST = 'ssl.request';
|
|
public const TYPE_SSL_RENEW = 'ssl.renew';
|
|
public const TYPE_DATABASE_CREATE = 'database.create';
|
|
public const TYPE_FILE_LIST = 'file.list';
|
|
public const TYPE_FILE_READ = 'file.read';
|
|
public const TYPE_FILE_WRITE = 'file.write';
|
|
public const TYPE_SITE_DELETE = 'site.delete';
|
|
public const TYPE_PHP_CONFIGURE = 'php.configure';
|
|
public const TYPE_CRON_LIST = 'cron.list';
|
|
public const TYPE_CRON_UPSERT = 'cron.upsert';
|
|
public const TYPE_CRON_REMOVE = 'cron.remove';
|
|
public const TYPE_LOG_READ = 'log.read';
|
|
|
|
protected $fillable = [
|
|
'customer_hosting_order_id',
|
|
'server_agent_id',
|
|
'lock_token',
|
|
'type',
|
|
'status',
|
|
'payload',
|
|
'result',
|
|
'progress',
|
|
'attempt_count',
|
|
'max_attempts',
|
|
'retry_backoff_seconds',
|
|
'stale_after_seconds',
|
|
'queued_at',
|
|
'available_at',
|
|
'started_at',
|
|
'completed_at',
|
|
'failed_at',
|
|
'last_heartbeat_at',
|
|
'locked_at',
|
|
'error_message',
|
|
];
|
|
|
|
protected $casts = [
|
|
'payload' => 'array',
|
|
'result' => 'array',
|
|
'queued_at' => 'datetime',
|
|
'available_at' => 'datetime',
|
|
'started_at' => 'datetime',
|
|
'completed_at' => 'datetime',
|
|
'failed_at' => 'datetime',
|
|
'last_heartbeat_at' => 'datetime',
|
|
'locked_at' => 'datetime',
|
|
];
|
|
|
|
public function order(): BelongsTo
|
|
{
|
|
return $this->belongsTo(CustomerHostingOrder::class, 'customer_hosting_order_id');
|
|
}
|
|
|
|
public function agent(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ServerAgent::class, 'server_agent_id');
|
|
}
|
|
|
|
public function sites(): HasMany
|
|
{
|
|
return $this->hasMany(ServerSite::class, 'latest_server_task_id');
|
|
}
|
|
|
|
public function databases(): HasMany
|
|
{
|
|
return $this->hasMany(ServerDatabase::class, 'latest_server_task_id');
|
|
}
|
|
|
|
public function files(): HasMany
|
|
{
|
|
return $this->hasMany(ServerFile::class, 'latest_server_task_id');
|
|
}
|
|
|
|
public function canRetry(bool $retryable = true): bool
|
|
{
|
|
return $retryable && $this->attempt_count < max(1, (int) $this->max_attempts);
|
|
}
|
|
}
|