Browse Source

v0.5.2 - add retry logic for payment received emails

main
def 1 month ago
parent
commit
77c829aea4
  1. 7
      README.md
  2. 2
      VERSION
  3. 11
      backend/app.py
  4. 6687
      backend/app.py.retry-email.20260327-023137.bak
  5. 6687
      backend/app.py.retry-email.20260327-023404.bak
  6. 60
      shell-scripts/email-retry-v2.sh
  7. 51
      shell-scripts/email-retry.sh

7
README.md

@ -1,3 +1,10 @@
## 2026-03-27 — v0.5.2
- Added retry logic for payment-received emails
- Payment email helper now retries up to 3 times with delay
- Added clearer retry failure logging for email send issues
## 2026-03-27 — v0.5.1 ## 2026-03-27 — v0.5.1
- Fixed crypto payment email auto-send path - Fixed crypto payment email auto-send path

2
VERSION

@ -1 +1 @@
v0.5.1 v0.5.2

11
backend/app.py

@ -1329,6 +1329,10 @@ support@outsidethebox.top
"data": pdf_bytes, "data": pdf_bytes,
}] }]
import time
for attempt in range(3):
try:
send_configured_email( send_configured_email(
to_email=invoice_email_row.get("email"), to_email=invoice_email_row.get("email"),
subject=subject, subject=subject,
@ -1338,6 +1342,13 @@ support@outsidethebox.top
invoice_id=invoice_id invoice_id=invoice_id
) )
return True return True
except Exception as e:
print(f"[email retry] invoice_id={invoice_id} attempt={attempt+1} error={type(e).__name__}: {e}")
if attempt < 2:
time.sleep(2)
print(f"[send_payment_received_email] FAILED after retries invoice_id={invoice_id}")
return False
except Exception: except Exception:
return False return False

6687
backend/app.py.retry-email.20260327-023137.bak

File diff suppressed because it is too large Load Diff

6687
backend/app.py.retry-email.20260327-023404.bak

File diff suppressed because it is too large Load Diff

60
shell-scripts/email-retry-v2.sh

@ -0,0 +1,60 @@
cd /home/def/otb_billing/backend || exit 1
STAMP="$(date +%Y%m%d-%H%M%S)"
cp app.py "app.py.retry-email.${STAMP}.bak"
python3 <<'PY'
from pathlib import Path
p = Path("app.py")
text = p.read_text()
old = ''' send_configured_email(
to_email=invoice_email_row.get("email"),
subject=subject,
body=body,
attachments=attachments,
email_type="payment_received",
invoice_id=invoice_id
)
return True
except Exception:
return False
'''
new = ''' import time
for attempt in range(3):
try:
send_configured_email(
to_email=invoice_email_row.get("email"),
subject=subject,
body=body,
attachments=attachments,
email_type="payment_received",
invoice_id=invoice_id
)
return True
except Exception as e:
print(f"[email retry] invoice_id={invoice_id} attempt={attempt+1} error={type(e).__name__}: {e}")
if attempt < 2:
time.sleep(2)
print(f"[send_payment_received_email] FAILED after retries invoice_id={invoice_id}")
return False
except Exception:
return False
'''
if old not in text:
raise SystemExit("FAILED: exact helper send block not found")
text = text.replace(old, new, 1)
p.write_text(text)
print("OK: retry logic added to helper")
PY
python3 -m py_compile app.py && echo "PY_COMPILE_OK" || echo "PY_COMPILE_FAILED"
sudo systemctl restart otb_billing
sudo systemctl status otb_billing --no-pager -l

51
shell-scripts/email-retry.sh

@ -0,0 +1,51 @@
cd /home/def/otb_billing/backend || exit 1
STAMP="$(date +%Y%m%d-%H%M%S)"
cp app.py "app.py.retry-email.${STAMP}.bak"
python3 <<'PY'
from pathlib import Path
p = Path("app.py")
text = p.read_text()
old = """ send_configured_email(
to_email=invoice_email_row.get("client_email"),
subject=subject,
html_body=html,
attachments=attachments
)
return True
except Exception:
return False
"""
new = """ import time
for attempt in range(3):
try:
send_configured_email(
to_email=invoice_email_row.get("client_email"),
subject=subject,
html_body=html,
attachments=attachments
)
return True
except Exception as e:
print(f"[email retry] attempt {attempt+1} failed: {e}")
time.sleep(2)
print(f"[send_payment_received_email] FAILED after retries invoice_id={invoice_id}")
return False
"""
if old not in text:
raise SystemExit("FAILED: send email block not found")
text = text.replace(old, new, 1)
p.write_text(text)
print("OK: retry logic added")
PY
python3 -m py_compile app.py && echo "PY_COMPILE_OK" || echo "PY_COMPILE_FAILED"
sudo systemctl restart otb_billing
Loading…
Cancel
Save