Files
portal-api/app/Jobs/DnsManager/SuspendDnsDomainJob.php
baodev0andClaude Opus 5.5 94614d9cb3 feat: khởi tạo/huỷ domain Plesk qua job, gửi mail hoá đơn qua queue, đính kèm triển khai
- ProvisionDnsDomainJob/SuspendDnsDomainJob: tạo domain admin lên Plesk, huỷ = suspend (is_created=3)
- Khách xem zone DNS được gán ở /dich-vu/domain, quản lý bản ghi A/AAAA/CNAME/TXT/MX/SRV
- send-mail hoá đơn đẩy SendInvoiceMailJob, preview + sửa nội dung, ghi mail.order_id
- invoice_attachments.type (payment_proof/deployment)
- CacheService xoá theo SCAN pattern, Redis không persistent mặc định
- Backfill transactions.public_code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 09:56:18 +07:00

49 lines
1.6 KiB
PHP

<?php
namespace App\Jobs\DnsManager;
use App\Models\DnsDomain;
use App\Models\DnsServer;
use App\Services\Plesk\PleskDomainService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use RuntimeException;
class SuspendDnsDomainJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public int $tries = 3;
public int $backoff = 60;
public function __construct(public readonly int $domainId) {}
public function handle(PleskDomainService $plesk): void
{
$domain = DnsDomain::find($this->domainId);
if (!$domain || (int) $domain->is_created !== DnsDomain::STATUS_CANCELLED) {
return;
}
$server = DnsServer::find($domain->dns_manager_server_id);
if (!$server) {
throw new RuntimeException("Không tìm thấy DNS server #{$domain->dns_manager_server_id} cho domain {$domain->domain_name}");
}
if (!$plesk->suspend($server, $domain->domain_name)) {
throw new RuntimeException("Không suspend được domain {$domain->domain_name} trên Plesk: " . ($plesk->getLastError() ?: 'không rõ lỗi'));
}
Log::info('DNS domain suspended on Plesk', ['domain' => $domain->domain_name, 'server_id' => $server->id]);
}
public function failed(\Throwable $e): void
{
Log::error('SuspendDnsDomainJob failed', ['domain_id' => $this->domainId, 'error' => $e->getMessage()]);
}
}