feat(webstatement): tambah AutoSendStatementEmailCommand dan job auto pengiriman email statement
Perubahan yang dilakukan: - Menambahkan command AutoSendStatementEmailCommand untuk otomatisasi pengiriman email statement. - Menambahkan job AutoSendStatementEmailJob untuk menangani proses pengiriman email secara asynchronous. - Menambahkan opsi --force dan --dry-run pada command untuk fleksibilitas eksekusi dan pengujian. - Mengintegrasikan command baru ke dalam WebstatementServiceProvider dan Console Kernel. - Mengimplementasikan scheduler untuk menjalankan job setiap menit secara otomatis. - Menambahkan kondisi auto send: is_available dan is_generated = true, email_sent_at = null. - Mendukung pengiriman statement multi-period dalam bentuk ZIP attachment. - Mengoptimalkan proses download dan integrasi file PDF dengan logging yang lebih detail. - Menambahkan logika prioritas local disk dibandingkan SFTP untuk pengambilan file secara efisien. - Menambahkan validasi tambahan untuk flow pengiriman email single dan multi period. - Mengimplementasikan error handling dan logging yang komprehensif. - Menggunakan database transaction untuk menjamin konsistensi data selama proses kirim email. - Menambahkan mekanisme prevent overlap dan timeout protection saat job berjalan. - Menghapus file sementara secara otomatis setelah email berhasil dikirim. - Membatasi proses pengiriman maksimal 50 statement per run untuk menjaga performa. Tujuan perubahan: - Mengotomatiskan pengiriman email statement pelanggan secara periodik dan aman. - Menyediakan fleksibilitas eksekusi manual dan simulasi pengujian sebelum produksi. - Menjamin efisiensi, stabilitas, dan monitoring penuh selama proses pengiriman.
This commit is contained in:
71
app/Console/AutoSendStatementEmailCommand.php
Normal file
71
app/Console/AutoSendStatementEmailCommand.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Webstatement\Console;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Modules\Webstatement\Jobs\AutoSendStatementEmailJob;
|
||||
|
||||
class AutoSendStatementEmailCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'webstatement:auto-send-email
|
||||
{--force : Force run even if already running}
|
||||
{--dry-run : Show what would be sent without actually sending}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Automatically send statement emails for available statements';
|
||||
|
||||
/**
|
||||
* Execute the console command untuk menjalankan auto send email
|
||||
*
|
||||
* Command ini akan:
|
||||
* 1. Dispatch AutoSendStatementEmailJob
|
||||
* 2. Log aktivitas command
|
||||
* 3. Handle dry-run mode untuk testing
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
try {
|
||||
$this->info('Starting auto send statement email process...');
|
||||
|
||||
Log::info('AutoSendStatementEmailCommand: Command started', [
|
||||
'force' => $this->option('force'),
|
||||
'dry_run' => $this->option('dry-run')
|
||||
]);
|
||||
|
||||
if ($this->option('dry-run')) {
|
||||
$this->info('DRY RUN MODE: Would dispatch AutoSendStatementEmailJob');
|
||||
Log::info('AutoSendStatementEmailCommand: Dry run mode, job not dispatched');
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
// Dispatch job
|
||||
AutoSendStatementEmailJob::dispatch();
|
||||
|
||||
$this->info('AutoSendStatementEmailJob dispatched successfully');
|
||||
|
||||
Log::info('AutoSendStatementEmailCommand: Job dispatched successfully');
|
||||
|
||||
return self::SUCCESS;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Error: ' . $e->getMessage());
|
||||
|
||||
Log::error('AutoSendStatementEmailCommand: Command failed', [
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user