From b894a2c9c456e042e7c7bc2353214056e2e435e4 Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Sat, 24 May 2025 16:12:33 +0700 Subject: [PATCH] feat(webstatement): tambahkan fitur schedule dan console command untuk migrasi dan ekspor data harian - Menambahkan dua console command baru: 1. `webstatement:process-daily-migration` untuk memproses migrasi data harian. 2. `webstatement:export-statements` untuk mengekspor laporan harian. - Mendefinisikan command `webstatement:process-daily-migration`: - Menggunakan `MigrasiController` untuk memproses data migrasi. - Menangkap error selama proses migrasi dan memberikan output informasi status. - Mendefinisikan command `webstatement:export-statements`: - Menggunakan `WebstatementController` untuk memproses ekspor laporan harian. - Memberikan informasi terkait jumlah job ekspor yang berhasil di-queue dan menangkap error selama proses. - Menambahkan schedule untuk kedua command: 1. `webstatement:process-daily-migration` dijalankan setiap hari pukul 09:00 dan log aktivitas disimpan di `daily-migration.log`. 2. `webstatement:export-statements` dijalankan setiap hari pukul 09:30 dan log aktivitas disimpan di `statement-export.log`. - Melengkapi `WebstatementServiceProvider` dengan pendaftaran command dan konfigurasi jadwal baru. Signed-off-by: Daeng Deni Mardaeni --- app/Console/ExportDailyStatements.php | 51 +++++++++++++++++++ app/Console/ProcessDailyMigration.php | 47 +++++++++++++++++ app/Providers/WebstatementServiceProvider.php | 19 ++++++- 3 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 app/Console/ExportDailyStatements.php create mode 100644 app/Console/ProcessDailyMigration.php diff --git a/app/Console/ExportDailyStatements.php b/app/Console/ExportDailyStatements.php new file mode 100644 index 0000000..d21348b --- /dev/null +++ b/app/Console/ExportDailyStatements.php @@ -0,0 +1,51 @@ +info('Starting daily statement export process...'); + + try { + $controller = app(WebstatementController::class); + $response = $controller->index(); + + $responseData = json_decode($response->getContent(), true); + $this->info($responseData['message']); + + // Display summary of jobs queued + $jobCount = count($responseData['jobs'] ?? []); + $this->info("Successfully queued {$jobCount} statement export jobs"); + + return Command::SUCCESS; + } catch (Exception $e) { + $this->error('Error exporting statements: ' . $e->getMessage()); + return Command::FAILURE; + } + } + } diff --git a/app/Console/ProcessDailyMigration.php b/app/Console/ProcessDailyMigration.php new file mode 100644 index 0000000..ec8e61b --- /dev/null +++ b/app/Console/ProcessDailyMigration.php @@ -0,0 +1,47 @@ +info('Starting daily data migration process...'); + + try { + $controller = app(MigrasiController::class); + $response = $controller->index(); + + $responseData = json_decode($response->getContent(), true); + $this->info($responseData['message'] ?? 'Process completed'); + + return Command::SUCCESS; + } catch (Exception $e) { + $this->error('Error processing daily migration: ' . $e->getMessage()); + return Command::FAILURE; + } + } + } diff --git a/app/Providers/WebstatementServiceProvider.php b/app/Providers/WebstatementServiceProvider.php index 3223524..ca25ffb 100644 --- a/app/Providers/WebstatementServiceProvider.php +++ b/app/Providers/WebstatementServiceProvider.php @@ -5,8 +5,10 @@ namespace Modules\Webstatement\Providers; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider; +use Modules\Webstatement\Console\ExportDailyStatements; use Modules\Webstatement\Console\GenerateBiayakartuCommand; use Modules\Webstatement\Console\GenerateBiayaKartuCsvCommand; +use Modules\Webstatement\Console\ProcessDailyMigration; use Modules\Webstatement\Jobs\UpdateAtmCardBranchCurrencyJob; use Nwidart\Modules\Traits\PathNamespace; @@ -52,7 +54,9 @@ class WebstatementServiceProvider extends ServiceProvider { $this->commands([ GenerateBiayakartuCommand::class, - GenerateBiayaKartuCsvCommand::class + GenerateBiayaKartuCsvCommand::class, + ProcessDailyMigration::class, + ExportDailyStatements::class, ]); } @@ -82,6 +86,19 @@ class WebstatementServiceProvider extends ServiceProvider ->appendOutputTo(storage_path('logs/biaya-kartu-csv-scheduler.log')); + // Schedule the daily migration process to run at 1:00 AM (from previous task) + $schedule->command('webstatement:process-daily-migration') + ->dailyAt('09:00') + ->withoutOverlapping() + ->appendOutputTo(storage_path('logs/daily-migration.log')); + + // Schedule the statement export to run at 2:00 AM (after migration is likely complete) + $schedule->command('webstatement:export-statements') + ->dailyAt('09:30') + ->withoutOverlapping() + ->appendOutputTo(storage_path('logs/statement-export.log')); + + } /**