$this->argument('permohonan-id'), 'created_by' => $this->argument('created-by'), 'sync' => $this->option('sync') ]); try { $permohonanId = (int) $this->argument('permohonan-id'); $createdBy = (int) $this->argument('created-by'); $sync = $this->option('sync'); $force = $this->option('force'); // Validasi input if ($permohonanId <= 0) { $this->error('Permohonan ID harus angka positif.'); return Command::FAILURE; } if ($createdBy <= 0) { $this->error('Created By harus angka positif.'); return Command::FAILURE; } // Tampilkan info $this->info('=== Cleanup Single Inspeksi ==='); $this->info("Permohonan ID: {$permohonanId}"); $this->info("Created By: {$createdBy}"); $this->info("Mode: " . ($sync ? 'Synchronous' : 'Queue')); $this->newLine(); // Konfirmasi jika tidak force if (!$force && !$this->confirm('Lanjutkan dengan cleanup?')) { $this->info('Cleanup dibatalkan.'); return Command::SUCCESS; } // Jalankan cleanup $cleanupService = new InspeksiCleanupService(); if ($sync) { $this->info('Menjalankan cleanup secara synchronous...'); $cleanupService->cleanupSync($permohonanId, $createdBy); $this->info('Cleanup selesai.'); } else { $this->info('Mengirim job ke queue...'); $cleanupService->cleanupAsync($permohonanId, $createdBy); $this->info('Job telah di-dispatch ke queue.'); $this->info('Monitor progress di log.'); } return Command::SUCCESS; } catch (\Exception $e) { Log::error('CleanupSingleInspeksiCommand: Terjadi error saat proses cleanup', [ 'permohonan_id' => $this->argument('permohonan-id'), 'created_by' => $this->argument('created-by'), 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); $this->error('Terjadi kesalahan: ' . $e->getMessage()); return Command::FAILURE; } } }