From 9dfb8727dc83041418a0971e9f6edfd030978929 Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Tue, 9 Dec 2025 15:24:44 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20service(InspeksiCleanupService):?= =?UTF-8?q?=20Implementasi=20service=20layer=20untuk=20manajemen=20cleanup?= =?UTF-8?q?=20data=20inspeksi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Membuat service layer yang menyediakan interface fleksibel untuk menjalankan cleanup data inspeksi secara async/sync dengan error handling dan logging komprehensif - Implementasi pattern service layer untuk separation of concerns - Method utama cleanupInspeksiData dengan parameter sync untuk fleksibilitas eksekusi - Method wrapper cleanupAsync() untuk eksekusi asynchronous default - Method wrapper cleanupSync() untuk eksekusi synchronous langsung - Error handling dengan try-catch dan re-throw exception untuk propagasi error - Logging informatif untuk setiap proses cleanup (mulai, selesai, error) - Integrasi dengan CleanupInspeksiDataJob untuk delegasi proses bisnis - Parameter lengkap: permohonanId, createdBy, dokumentId, dan sync mode - Dokumentasi PHPDoc yang komprehensif untuk setiap method - Menggunakan Laravel dispatch() untuk queue management yang optimal --- app/Services/InspeksiCleanupService.php | 83 +++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 app/Services/InspeksiCleanupService.php 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