Set status P (processing) before send, revert to S on failure

Prevents UI re-trigger while email is in flight. Status flow:
S (scheduled) → P (processing) → D (delivered) / S (failed, retryable)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
sas.fajri
2026-05-24 22:04:06 +07:00
parent d83f0f303b
commit 409c156310

View File

@@ -268,7 +268,7 @@ $sql = "
LEFT JOIN m_patient p
ON p.M_PatientID = oh.T_OrderHeaderM_PatientID
WHERE e.T_SendEmailIsActive = 'Y'
AND e.T_SendEmailStatus = 'S'
AND e.T_SendEmailStatus IN ('S')
AND e.T_SendEmailCount < {$max_retry}
{$where_id}
ORDER BY e.T_SendEmailID ASC
@@ -350,6 +350,14 @@ foreach ($rows as $row) {
continue;
}
// Lock: tandai sedang dikirim agar tidak bisa di-trigger ulang dari UI
$pdo->prepare("
UPDATE t_send_email
SET T_SendEmailStatus = 'P',
T_SendEmailLastUpdated = NOW()
WHERE T_SendEmailID = ?
")->execute([$id]);
$err = send_email(
$smtp,
$from_addr,
@@ -396,7 +404,8 @@ foreach ($rows as $row) {
log_msg(" Error: {$err}");
$pdo->prepare("
UPDATE t_send_email
SET T_SendEmailCount = T_SendEmailCount + 1,
SET T_SendEmailStatus = 'S',
T_SendEmailCount = T_SendEmailCount + 1,
T_SendEmailResponse = ?,
T_SendEmailLastUpdated = NOW()
WHERE T_SendEmailID = ?