fix(jobs): perbaikan masalah file tidak ditemukan pada proses export statement
Perubahan yang dilakukan: - Penambahan Debugging dan Verifikasi Storage: - Menambahkan log detail untuk tracking proses export CSV, termasuk informasi disk, client, account number, period, dan path penyimpanan. - Mengimplementasikan pembuatan file dummy untuk memverifikasi fungsi storage disk sebelum proses export dijalankan. - Menambahkan verifikasi keberadaan file setelah proses export selesai untuk memastikan file benar-benar tersimpan di storage. - Perbaikan Manajemen Path: - Memastikan seluruh proses pembuatan direktori menggunakan Laravel Storage facade secara konsisten. - Menghapus dependency pada proses sistem chmod, chown, dan chgrp yang berpotensi menimbulkan masalah portabilitas. - Menggunakan path absolut dan konsisten untuk menghindari konflik direktori atau kesalahan path relatif. - Peningkatan Error Handling: - Menambahkan log error khusus jika storage disk tidak berfungsi dengan baik atau tidak dapat diakses. - Mengimplementasikan cleanup file dummy setelah proses verifikasi storage selesai. - Menambahkan informasi log tambahan untuk kebutuhan debugging dan troubleshooting di lingkungan production. - Optimasi Performa: - Menggunakan Laravel Storage facade sebagai standar pembuatan direktori dan file untuk efisiensi dan konsistensi. - Mengurangi overhead dari pemanggilan fungsi sistem operasi yang tidak diperlukan. - Memastikan fungsionalitas utama tetap berjalan dengan lebih andal tanpa perubahan pada logika bisnis utama. Tujuan perubahan: - Memastikan file export statement benar-benar tersimpan dan dapat diakses, tidak hanya tercatat sukses di log. - Mengatasi masalah di mana proses log mencatat keberhasilan export tetapi file tidak ditemukan di sistem file. - Meningkatkan reliabilitas sistem export dengan verifikasi berlapis pada proses penyimpanan. - Menyederhanakan proses penulisan file agar lebih portable, aman, dan mudah di-maintain di berbagai environment.
This commit is contained in:
@@ -81,10 +81,10 @@
|
|||||||
$existingDataCount = $this->getExistingProcessedCount($accountQuery);
|
$existingDataCount = $this->getExistingProcessedCount($accountQuery);
|
||||||
|
|
||||||
// Hanya proses jika data belum lengkap diproses
|
// Hanya proses jika data belum lengkap diproses
|
||||||
if ($existingDataCount !== $totalCount) {
|
//if ($existingDataCount !== $totalCount) {
|
||||||
$this->deleteExistingProcessedData($accountQuery);
|
$this->deleteExistingProcessedData($accountQuery);
|
||||||
$this->processAndSaveStatementEntries($totalCount);
|
$this->processAndSaveStatementEntries($totalCount);
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getTotalEntryCount(array $criteria)
|
private function getTotalEntryCount(array $criteria)
|
||||||
@@ -357,8 +357,7 @@
|
|||||||
/**
|
/**
|
||||||
* Export processed data to CSV file
|
* Export processed data to CSV file
|
||||||
*/
|
*/
|
||||||
private function exportToCsv()
|
private function exportToCsv(): void
|
||||||
: void
|
|
||||||
{
|
{
|
||||||
// Determine the base path based on client
|
// Determine the base path based on client
|
||||||
$basePath = !empty($this->client)
|
$basePath = !empty($this->client)
|
||||||
@@ -367,14 +366,11 @@
|
|||||||
|
|
||||||
$accountPath = "{$basePath}/{$this->account_number}";
|
$accountPath = "{$basePath}/{$this->account_number}";
|
||||||
|
|
||||||
// Create client directory if it doesn't exist
|
// PERBAIKAN: Selalu pastikan direktori dibuat
|
||||||
if (!empty($this->client)) {
|
Storage::disk($this->disk)->makeDirectory($basePath);
|
||||||
// Di fungsi exportToCsv untuk basePath
|
Storage::disk($this->disk)->makeDirectory($accountPath);
|
||||||
Storage::disk($this->disk)->makeDirectory($basePath);
|
|
||||||
|
|
||||||
// Untuk accountPath
|
|
||||||
Storage::disk($this->disk)->makeDirectory($accountPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
$filePath = "{$accountPath}/{$this->fileName}";
|
$filePath = "{$accountPath}/{$this->fileName}";
|
||||||
|
|
||||||
@@ -383,13 +379,38 @@
|
|||||||
Storage::disk($this->disk)->delete($filePath);
|
Storage::disk($this->disk)->delete($filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
$csvContent = "NO|TRANSACTION.DATE|REFERENCE.NUMBER|TRANSACTION.AMOUNT|TRANSACTION.TYPE|DESCRIPTION|END.BALANCE|ACTUAL.DATE|NO.RECEIPT\n";
|
|
||||||
|
|
||||||
// Ambil data yang sudah diproses dalam chunk untuk mengurangi penggunaan memori
|
// Tambahkan di awal fungsi exportToCsv
|
||||||
|
Log::info("Starting CSV export", [
|
||||||
|
'disk' => $this->disk,
|
||||||
|
'client' => $this->client,
|
||||||
|
'account_number' => $this->account_number,
|
||||||
|
'period' => $this->period,
|
||||||
|
'base_path' => $basePath,
|
||||||
|
'account_path' => $accountPath,
|
||||||
|
'file_path' => $filePath
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Cek apakah disk storage berfungsi
|
||||||
|
$testFile = 'test_' . time() . '.txt';
|
||||||
|
Storage::disk($this->disk)->put($testFile, 'test content');
|
||||||
|
if (Storage::disk($this->disk)->exists($testFile)) {
|
||||||
|
Log::info("Storage disk is working");
|
||||||
|
Storage::disk($this->disk)->delete($testFile);
|
||||||
|
} else {
|
||||||
|
Log::error("Storage disk is not working properly");
|
||||||
|
}
|
||||||
|
|
||||||
|
// PERBAIKAN: Buat file header terlebih dahulu
|
||||||
|
$csvContent = "NO|TRANSACTION.DATE|REFERENCE.NUMBER|TRANSACTION.AMOUNT|TRANSACTION.TYPE|DESCRIPTION|END.BALANCE|ACTUAL.DATE|NO.RECEIPT\n";
|
||||||
|
Storage::disk($this->disk)->put($filePath, $csvContent);
|
||||||
|
|
||||||
|
// Ambil data yang sudah diproses dalam chunk
|
||||||
ProcessedStatement::where('account_number', $this->account_number)
|
ProcessedStatement::where('account_number', $this->account_number)
|
||||||
->where('period', $this->period)
|
->where('period', $this->period)
|
||||||
->orderBy('sequence_no')
|
->orderBy('sequence_no')
|
||||||
->chunk($this->chunkSize, function ($statements) use (&$csvContent, $filePath) {
|
->chunk($this->chunkSize, function ($statements) use ($filePath) {
|
||||||
|
$csvContent = '';
|
||||||
foreach ($statements as $statement) {
|
foreach ($statements as $statement) {
|
||||||
$csvContent .= implode('|', [
|
$csvContent .= implode('|', [
|
||||||
$statement->sequence_no,
|
$statement->sequence_no,
|
||||||
@@ -404,12 +425,31 @@
|
|||||||
]) . "\n";
|
]) . "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tulis ke file secara bertahap untuk mengurangi penggunaan memori
|
// Append ke file
|
||||||
Storage::disk($this->disk)->append($filePath, $csvContent);
|
if (!empty($csvContent)) {
|
||||||
$csvContent = ''; // Reset content setelah ditulis
|
Storage::disk($this->disk)->append($filePath, $csvContent);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Log::info("Statement exported to {$this->disk} disk: {$filePath}");
|
// PERBAIKAN: Verifikasi file benar-benar ada
|
||||||
|
if (Storage::disk($this->disk)->exists($filePath)) {
|
||||||
|
$fileSize = Storage::disk($this->disk)->size($filePath);
|
||||||
|
Log::info("Statement exported successfully", [
|
||||||
|
'disk' => $this->disk,
|
||||||
|
'file_path' => $filePath,
|
||||||
|
'file_size' => $fileSize,
|
||||||
|
'account_number' => $this->account_number,
|
||||||
|
'period' => $this->period
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
Log::error("File was not created despite successful processing", [
|
||||||
|
'disk' => $this->disk,
|
||||||
|
'file_path' => $filePath,
|
||||||
|
'account_number' => $this->account_number,
|
||||||
|
'period' => $this->period
|
||||||
|
]);
|
||||||
|
throw new \Exception("Failed to create CSV file: {$filePath}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user