Files
portal-api/app/Support/QueueJobInspector.php
T
baodev0andClaude Sonnet 5.5 62596d9063 feat(vm): hoàn tiền khi cấp VM lỗi, theo dõi job queue, uuid dịch vụ cho ticket, chuẩn hoá RAM addon
- VmProvisionException/VmProvisionRefund xử lý lỗi cấp phát VM
- QueueJobInspector + QueueMonitorController xem chi tiết job
- Thêm service uuid cho ticket, thời lượng cho activity_logs
- Migration chuẩn hoá RAM addon sang MB, trạng thái deleting cho snapshot

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 11:54:05 +07:00

67 lines
2.4 KiB
PHP

<?php
namespace App\Support;
class QueueJobInspector
{
private const SENSITIVE = '/pass|secret|token|key|otp|code/i';
public static function describe(object $job): array
{
$payload = json_decode($job->payload ?? '', true) ?: [];
$command = $payload['data']['command'] ?? null;
unset($payload['data']['command']);
return [
'id' => $job->id,
'name' => $payload['displayName'] ?? $job->name ?? null,
'connection' => $job->connection ?? null,
'queue' => $job->queue ?? null,
'status' => $job->status ?? null,
'attempts' => $payload['attempts'] ?? 0,
'max_tries' => $payload['maxTries'] ?? null,
'timeout' => $payload['timeout'] ?? null,
'tags' => $payload['tags'] ?? [],
'pushed_at' => self::iso($payload['pushedAt'] ?? null),
'reserved_at' => self::iso($job->reserved_at ?? null),
'completed_at' => self::iso($job->completed_at ?? null),
'failed_at' => self::iso($job->failed_at ?? null),
'retried_by' => json_decode($job->retried_by ?? '[]', true) ?: [],
'properties' => is_string($command) ? self::properties($command) : [],
'exception' => $job->exception ?? null,
'context' => json_decode($job->context ?? 'null', true),
'payload' => $payload,
];
}
private static function properties(string $serialized): array
{
preg_match_all(
'/s:\d+:"(?:\x00[^\x00]*\x00)?(\w+)";(?:i:(-?\d+)|d:([-\d.eE+]+)|b:([01])|s:\d+:"(.*?)"|N);/s',
$serialized,
$matches,
PREG_SET_ORDER
);
$properties = [];
foreach ($matches as $m) {
$name = $m[1];
$value = match (true) {
($m[2] ?? '') !== '' => (int) $m[2],
($m[3] ?? '') !== '' => (float) $m[3],
($m[4] ?? '') !== '' => $m[4] === '1',
array_key_exists(5, $m) && $m[5] !== '' => $m[5],
default => null,
};
$properties[$name] = preg_match(self::SENSITIVE, $name) && $value !== null ? '********' : $value;
}
return $properties;
}
private static function iso(int|float|string|null $ts): ?string
{
return $ts ? \Carbon\Carbon::createFromTimestamp((int) $ts)->toIso8601String() : null;
}
}