7 changed files with 13513 additions and 10 deletions
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -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 |
||||||
|
|
||||||
@ -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…
Reference in new issue