lthn.io/app/Mod/Names/Commands/RetryDnsTickets.php
Claude 1ef6ed1c7b
refactor: move DNS tickets from Cache to DnsTicket database model
DNS change tickets now persisted in MariaDB via DnsTicket model.
Survives cache clears and container rebuilds. Model has open(),
confirm(), fail() methods and pending/queued scopes. Controller
updateRecords and ticket endpoints refactored. RetryDnsTickets
command queries model instead of cache.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 12:06:00 +01:00

68 lines
2 KiB
PHP

<?php
declare(strict_types=1);
namespace Mod\Names\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
use Mod\Chain\Services\DaemonRpc;
use Mod\Chain\Services\WalletRpc;
use Mod\Names\Models\DnsTicket;
/**
* php artisan names:retry-dns
*
* Retries queued DNS change tickets and confirms pending ones.
*/
class RetryDnsTickets extends Command
{
protected $signature = 'names:retry-dns';
protected $description = 'Retry queued DNS change tickets';
public function handle(DaemonRpc $rpc, WalletRpc $wallet): int
{
$retried = 0;
$confirmed = 0;
// Confirm pending tickets
DnsTicket::pending()->each(function (DnsTicket $ticket) use ($rpc, &$confirmed) {
if (! $ticket->tx_id) {
return;
}
$alias = $rpc->getAliasByName($ticket->name);
if ($alias && str_contains($alias['comment'] ?? '', 'dns=')) {
$ticket->confirm();
Cache::forget("dns_edit_lock:{$ticket->name}");
$confirmed++;
$this->line(" Confirmed: {$ticket->name} (ticket {$ticket->ticket_id})");
}
});
// Retry queued tickets
DnsTicket::queued()->each(function (DnsTicket $ticket) use ($wallet, &$retried) {
$result = $wallet->updateAlias(
$ticket->name,
$ticket->address ?? '',
$ticket->comment ?? ''
);
if (isset($result['tx_id'])) {
$ticket->update([
'status' => 'pending',
'tx_id' => $result['tx_id'],
]);
$retried++;
$this->line(" Retried: {$ticket->name} → tx {$result['tx_id']}");
} else {
$this->line(" Still queued: {$ticket->name}" . ($result['error'] ?? 'chain busy'));
}
});
$this->info("Done. Retried: {$retried}, Confirmed: {$confirmed}");
return 0;
}
}