feat(webstatement): tambah parameter period ke ProcessDailyMigration command
Menambahkan parameter --period pada command ProcessDailyMigration untuk fleksibilitas pemrosesan data harian. Perubahan yang dilakukan: - Menambahkan parameter --period dengan default '-1 day' pada command ProcessDailyMigration - Memungkinkan input period dalam berbagai format: - Format Ymd (contoh: 20250120) - Format relative date (contoh: '-2 days', '-1 week') - Default fallback ke '-1 day' jika parameter kosong atau format tidak valid - Update method index di MigrasiController untuk menerima dan memproses parameter period - Menambahkan method determinePeriod untuk konversi dan validasi parameter period - Menggunakan Carbon untuk parsing dan konversi tanggal - Menambahkan logging detail untuk tracking parameter input dan hasil konversi period - Menambahkan validasi dan error handling jika format periode tidak sesuai - Mempertahankan backward compatibility agar command lama tetap berjalan seperti sebelumnya - Update deskripsi command dan signature agar dokumentasi CLI lebih jelas Tujuan perubahan: - Memberikan fleksibilitas bagi tim operasional untuk menjalankan migrasi data dengan periode yang spesifik - Memudahkan eksekusi ulang data harian atau data backdate tanpa modifikasi kode - Memastikan proses migrasi lebih aman, transparan, dan dapat dipantau melalui logging
This commit is contained in:
@@ -1,51 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Webstatement\Console;
|
||||
namespace Modules\Webstatement\Console;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Modules\Webstatement\Http\Controllers\MigrasiController;
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Modules\Webstatement\Http\Controllers\MigrasiController;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ProcessDailyMigration extends Command
|
||||
class ProcessDailyMigration extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'webstatement:process-daily-migration
|
||||
{--process_parameter= : To process migration parameter true/false}
|
||||
{--period= : Period to process (default: -1 day, format: Ymd or relative date)}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Process data migration for the specified period (default: previous day)';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'webstatement:process-daily-migration
|
||||
{--process_parameter= : To process migration parameter true/false}';
|
||||
$processParameter = $this->option('process_parameter');
|
||||
$period = $this->option('period');
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Process data migration for the previous day\'s period';
|
||||
// Log start of process
|
||||
Log::info('Starting daily data migration process', [
|
||||
'process_parameter' => $processParameter ?? 'false',
|
||||
'period' => $period ?? '-1 day'
|
||||
]);
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$processParameter = $this->option('process_parameter');
|
||||
$this->info('Starting daily data migration process...');
|
||||
$this->info('Process Parameter: ' . ($processParameter ?? 'False'));
|
||||
$this->info('Period: ' . ($period ?? '-1 day (default)'));
|
||||
|
||||
$this->info('Starting daily data migration process...');
|
||||
$this->info('Process Parameter: ' . ($processParameter ?? 'False'));
|
||||
try {
|
||||
$controller = app(MigrasiController::class);
|
||||
$response = $controller->index($processParameter, $period);
|
||||
|
||||
try {
|
||||
$controller = app(MigrasiController::class);
|
||||
$response = $controller->index($processParameter);
|
||||
$responseData = json_decode($response->getContent(), true);
|
||||
$message = $responseData['message'] ?? 'Process completed';
|
||||
|
||||
$responseData = json_decode($response->getContent(), true);
|
||||
$this->info($responseData['message'] ?? 'Process completed');
|
||||
$this->info($message);
|
||||
Log::info('Daily migration process completed successfully', ['message' => $message]);
|
||||
|
||||
return Command::SUCCESS;
|
||||
} catch (Exception $e) {
|
||||
$this->error('Error processing daily migration: ' . $e->getMessage());
|
||||
return Command::FAILURE;
|
||||
}
|
||||
return Command::SUCCESS;
|
||||
} catch (Exception $e) {
|
||||
$errorMessage = 'Error processing daily migration: ' . $e->getMessage();
|
||||
$this->error($errorMessage);
|
||||
Log::error($errorMessage, ['exception' => $e->getTraceAsString()]);
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user