diff --git a/app/Services/InspeksiCleanupService.php b/app/Services/InspeksiCleanupService.php new file mode 100644 index 0000000..1581392 --- /dev/null +++ b/app/Services/InspeksiCleanupService.php @@ -0,0 +1,83 @@ + $permohonanId, + 'created_by' => $createdBy, + 'dokument_id' => $dokumentId, + 'sync' => $sync + ]); + + try { + $job = new CleanupInspeksiDataJob($permohonanId, $createdBy, $dokumentId); + + if ($sync) { + // Jalankan secara synchronous (langsung) + $job->handle(); + Log::info('InspeksiCleanupService: Cleanup selesai dijalankan secara sync'); + } else { + // Dispatch ke queue + dispatch($job); + Log::info('InspeksiCleanupService: Cleanup job berhasil di-dispatch ke queue'); + } + } catch (\Exception $e) { + Log::error('InspeksiCleanupService: Gagal menjalankan cleanup', [ + 'permohonan_id' => $permohonanId, + 'created_by' => $createdBy, + 'error' => $e->getMessage(), + 'trace' => $e->getTraceAsString() + ]); + + throw $e; + } + } + + /** + * Dispatch job untuk cleanup data inspeksi secara async (default) + * + * @param int $permohonanId + * @param int $createdBy + * @param int|null $dokumentId + * @return void + */ + public function cleanupAsync(int $permohonanId, int $createdBy, ?int $dokumentId = null): void + { + $this->cleanupInspeksiData($permohonanId, $createdBy, $dokumentId, false); + } + + /** + * Jalankan cleanup data inspeksi secara sync + * + * @param int $permohonanId + * @param int $createdBy + * @param int|null $dokumentId + * @return void + */ + public function cleanupSync(int $permohonanId, int $createdBy, ?int $dokumentId = null): void + { + $this->cleanupInspeksiData($permohonanId, $createdBy, $dokumentId, true); + } +} \ No newline at end of file