fix: Adjust memory threshold for Discord message sending and improve error logging
This commit is contained in:
parent
519cb25038
commit
ce816af9e7
@ -60,19 +60,19 @@ def send_discord_message(message, username="Auto Garden Bot", is_alert=False, de
|
|||||||
# Quick mem check before importing urequests/SSL
|
# Quick mem check before importing urequests/SSL
|
||||||
mem = getattr(gc, "mem_free", lambda: None)()
|
mem = getattr(gc, "mem_free", lambda: None)()
|
||||||
# Require larger headroom based on device testing (adjust if you re-test)
|
# Require larger headroom based on device testing (adjust if you re-test)
|
||||||
if mem is not None and mem < 150000:
|
if mem is not None and mem < 105000:
|
||||||
# quietly skip send when memory is insufficient
|
print("Discord send skipped: ENOMEM ({} bytes free)".format(mem))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Import urequests only when we plan to send
|
# Import urequests only when we plan to send
|
||||||
try:
|
try:
|
||||||
import urequests as requests # type: ignore
|
import urequests as requests # type: ignore
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
print("Discord send failed: urequests import error:", e)
|
||||||
try:
|
try:
|
||||||
_NEXT_ALLOWED_SEND_TS = time.time() + 60
|
_NEXT_ALLOWED_SEND_TS = time.time() + 60
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
# quiet failure to avoid spamming serial; caller can check return value
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
gc.collect()
|
gc.collect()
|
||||||
@ -93,14 +93,13 @@ def send_discord_message(message, username="Auto Garden Bot", is_alert=False, de
|
|||||||
return bool(status and 200 <= status < 300)
|
return bool(status and 200 <= status < 300)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# On ENOMEM/MemoryError back off
|
print("Discord send failed:", e)
|
||||||
try:
|
try:
|
||||||
if ("ENOMEM" in str(e)) or isinstance(e, MemoryError):
|
if ("ENOMEM" in str(e)) or isinstance(e, MemoryError):
|
||||||
import time # type: ignore
|
import time # type: ignore
|
||||||
_NEXT_ALLOWED_SEND_TS = time.time() + 60
|
_NEXT_ALLOWED_SEND_TS = time.time() + 60
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
# quiet exception path; return False for caller to handle/backoff
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user