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 <ddeni05@gmail.com>
This commit is contained in:
51
app/Console/ExportDailyStatements.php
Normal file
51
app/Console/ExportDailyStatements.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Webstatement\Console;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Modules\Webstatement\Http\Controllers\WebstatementController;
|
||||
|
||||
class ExportDailyStatements extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'webstatement:export-statements';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Export daily statements for all configured client accounts';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
}
|
||||
47
app/Console/ProcessDailyMigration.php
Normal file
47
app/Console/ProcessDailyMigration.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Webstatement\Console;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Modules\Webstatement\Http\Controllers\MigrasiController;
|
||||
|
||||
class ProcessDailyMigration extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'webstatement:process-daily-migration';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Process data migration for the previous day\'s period';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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'));
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user