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>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
30898ea46f
commit
94614d9cb3
@@ -0,0 +1,57 @@
|
||||
<?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 ProvisionDnsDomainJob 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 || $domain->plesk_id) {
|
||||
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}");
|
||||
}
|
||||
|
||||
$pleskDomain = $plesk->getDomainInfo($server, $domain->domain_name)
|
||||
?: $plesk->createDomain($server, ['domain_name' => $domain->domain_name]);
|
||||
|
||||
if (empty($pleskDomain['id'])) {
|
||||
throw new RuntimeException("Không tạo được domain {$domain->domain_name} trên Plesk: " . ($plesk->getLastError() ?? 'không rõ lỗi'));
|
||||
}
|
||||
|
||||
$domain->forceFill(['plesk_id' => $pleskDomain['id'], 'is_created' => 1])->save();
|
||||
|
||||
Log::info('DNS domain provisioned on Plesk', [
|
||||
'domain' => $domain->domain_name,
|
||||
'server_id' => $server->id,
|
||||
'plesk_id' => $pleskDomain['id'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function failed(\Throwable $e): void
|
||||
{
|
||||
Log::error('ProvisionDnsDomainJob failed', ['domain_id' => $this->domainId, 'error' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user