feat(webstatement): tambahkan fitur retry dengan handling timeout pada laporan transaksi ATM
- Memperbarui logika retry pada `AtmTransactionReportController`: - Memperbolehkan retry jika status laporan adalah `failed`, `pending`, atau laporan dengan status `processing` yang telah melebihi batas waktu (1 jam). - Menambahkan atribut baru seperti `processing_hours` dan `is_processing_timeout` pada data untuk menampilkan informasi durasi proses dan flag timeout. - Mengubah status laporan menjadi `failed` jika melebihi batas waktu sebelum dilakukan retry. - Memperbarui error message untuk mencatat alasan timeout. - Menambahkan metode baru `canRetry` pada controller: - Mengembalikan boolean jika laporan dapat di-retry berdasarkan status dan kondisi laporan. - Memperbarui tampilan untuk bagian daftar laporan (`atm-reports/index.blade.php`): - Menambahkan tombol retry dengan warna yang disesuaikan (kuning/oranye untuk `failed`/`pending`, merah untuk timeout). - Memperbarui tampilan status laporan menjadi lebih informatif, termasuk keterangan durasi proses jika timeout. - Memperbarui tampilan detail laporan (`atm-reports/show.blade.php`): - Menambahkan tombol retry dengan label tambahan "Retry (Timeout)" jika melebihi batas waktu proses. - Menampilkan informasi tambahan seperti waktu proses jika laporan dalam status `processing`. - Menyediakan fungsi JavaScript baru `retryReport` untuk handling retry via AJAX: - Menyertakan konfirmasi sebelum retry. - Memperbarui tombol retry agar lebih reaktif terhadap perubahan status laporan. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
@@ -133,7 +133,7 @@
|
||||
type: 'DELETE'
|
||||
}).then((response) => {
|
||||
swal.fire('Deleted!', 'ATM Transaction report has been deleted.', 'success').then(
|
||||
() => {
|
||||
() => {
|
||||
window.location.reload();
|
||||
});
|
||||
}).catch((error) => {
|
||||
@@ -143,6 +143,40 @@
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Add the missing retryReport function
|
||||
function retryReport(id) {
|
||||
Swal.fire({
|
||||
title: 'Are you sure?',
|
||||
text: 'This will reset the current job and start a new one.',
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#3085d6',
|
||||
cancelButtonColor: '#d33',
|
||||
confirmButtonText: 'Yes, retry it!'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
$.ajaxSetup({
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
||||
}
|
||||
});
|
||||
|
||||
$.ajax(`atm-reports/${id}/retry`, {
|
||||
type: 'POST'
|
||||
}).then((response) => {
|
||||
Swal.fire('Success!', 'Report retry initiated successfully.', 'success').then(
|
||||
() => {
|
||||
window.location.reload();
|
||||
});
|
||||
}).catch((error) => {
|
||||
console.error('Error:', error);
|
||||
Swal.fire('Error!', 'Failed to retry report: ' + (error.responseJSON?.message ||
|
||||
'Unknown error'), 'error');
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<script type="module">
|
||||
@@ -183,18 +217,24 @@
|
||||
title: 'Status',
|
||||
render: (item, data) => {
|
||||
let statusClass = 'badge badge-light-primary';
|
||||
let statusText = data.status;
|
||||
|
||||
if (data.status === 'completed') {
|
||||
statusClass = 'badge badge-light-success';
|
||||
} else if (data.status === 'failed') {
|
||||
statusClass = 'badge badge-light-danger';
|
||||
} else if (data.status === 'processing') {
|
||||
statusClass = 'badge badge-light-warning';
|
||||
if (data.is_processing_timeout) {
|
||||
statusClass = 'badge badge-light-danger';
|
||||
statusText += ` (${data.processing_hours}h)`;
|
||||
} else {
|
||||
statusClass = 'badge badge-light-warning';
|
||||
}
|
||||
} else if (data.status === 'pending') {
|
||||
statusClass = 'badge badge-light-info';
|
||||
}
|
||||
|
||||
return `<span class="${statusClass}">${data.status}</span>`;
|
||||
return `<span class="${statusClass}">${statusText}</span>`;
|
||||
},
|
||||
},
|
||||
authorization_status: {
|
||||
@@ -234,6 +274,17 @@
|
||||
</a>`;
|
||||
}
|
||||
|
||||
// Retry button
|
||||
if (data.can_retry) {
|
||||
let retryClass = 'btn-warning';
|
||||
if (data.is_processing_timeout) {
|
||||
retryClass = 'btn-danger';
|
||||
}
|
||||
buttons += `<button class="btn btn-sm btn-icon btn-clear ${retryClass}" onclick="retryReport(${data.id})">
|
||||
<i class="ki-outline ki-arrows-circle"></i>
|
||||
</button>`;
|
||||
}
|
||||
|
||||
// Only show delete button if status is pending or failed
|
||||
if (data.status === 'pending' || data.status === 'failed') {
|
||||
buttons += `<a onclick="deleteData(${data.id})" class="delete btn btn-sm btn-icon btn-clear btn-danger">
|
||||
@@ -241,31 +292,6 @@
|
||||
</a>`;
|
||||
}
|
||||
|
||||
// Di bagian JavaScript untuk action buttons
|
||||
if (data.status === 'failed' || data.status === 'pending' || (data.status === 'completed' && !data.file_path)) {
|
||||
buttons += `<button class="btn btn-sm btn-icon btn-clear btn-warning" onclick="retryReport(${data.id})" title="Retry Job">
|
||||
<i class="ki-duotone ki-arrows-circle fs-5"></i>
|
||||
</button>`;
|
||||
}
|
||||
|
||||
// Tambahkan function untuk retry
|
||||
function retryReport(id) {
|
||||
if (confirm('Are you sure you want to retry generating this report?')) {
|
||||
$.ajax({
|
||||
url: `atm-reports/${id}/retry`,
|
||||
type: 'POST',
|
||||
data: {
|
||||
_token: $('meta[name="csrf-token"]').attr('content')
|
||||
},
|
||||
success: function(response) {
|
||||
location.reload();
|
||||
},
|
||||
error: function(xhr) {
|
||||
alert('Error: ' + xhr.responseJSON.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
buttons += `</div>`;
|
||||
return buttons;
|
||||
},
|
||||
|
||||
@@ -15,11 +15,22 @@
|
||||
</a>
|
||||
@endif
|
||||
|
||||
@if (in_array($atmReport->status, ['failed', 'pending']) || ($atmReport->status === 'completed' && !$atmReport->file_path))
|
||||
@php
|
||||
$canRetry = in_array($atmReport->status, ['failed', 'pending']) ||
|
||||
($atmReport->status === 'processing' && $atmReport->updated_at->diffInHours(now()) >= 1) ||
|
||||
($atmReport->status === 'completed' && !$atmReport->file_path);
|
||||
@endphp
|
||||
|
||||
@if ($canRetry)
|
||||
<form action="{{ route('atm-reports.retry', $atmReport->id) }}" method="POST" class="d-inline" onsubmit="return confirm('Are you sure you want to retry generating this report?')">
|
||||
@csrf
|
||||
<button type="submit" class="btn btn-sm btn-warning me-2">
|
||||
<i class="ki-duotone ki-arrows-circle fs-2"></i>Retry Job
|
||||
<i class="ki-duotone ki-arrows-circle fs-2"></i>
|
||||
@if($atmReport->status === 'processing' && $atmReport->updated_at->diffInHours(now()) >= 1)
|
||||
Retry (Timeout)
|
||||
@else
|
||||
Retry Job
|
||||
@endif
|
||||
</button>
|
||||
</form>
|
||||
@endif
|
||||
@@ -72,7 +83,20 @@
|
||||
@if ($atmReport->status === 'pending')
|
||||
<span class="badge badge-info">Pending</span>
|
||||
@elseif($atmReport->status === 'processing')
|
||||
<span class="badge badge-warning">Processing</span>
|
||||
@php
|
||||
$processingHours = $atmReport->updated_at->diffInHours(now());
|
||||
@endphp
|
||||
<span class="badge {{ $processingHours >= 1 ? 'badge-danger' : 'badge-warning' }}">
|
||||
Processing
|
||||
@if($processingHours >= 1)
|
||||
({{ $processingHours }}h - Timeout)
|
||||
@endif
|
||||
</span>
|
||||
@if($processingHours >= 1)
|
||||
<div class="mt-1 text-danger small">
|
||||
Processing for more than 1 hour. You can retry this job.
|
||||
</div>
|
||||
@endif
|
||||
@elseif($atmReport->status === 'completed')
|
||||
<span class="badge badge-success">Completed</span>
|
||||
@elseif($atmReport->status === 'failed')
|
||||
|
||||
Reference in New Issue
Block a user