Skip to content

Commit

Permalink
Merge pull request #128 from dave-ct/low_disk_space_upload
Browse files Browse the repository at this point in the history
Attempt to upload cached files when low disk space
  • Loading branch information
ZodiusInfuser authored Dec 13, 2022
2 parents d091f75 + 02a99f6 commit d47dd7a
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@
# from phew import logging
# logging.disable_logging_types(logging.LOG_DEBUG)

# Issue #117 where neeed to sleep on startup otherwis emight not boot
from time import sleep
sleep(0.5)

# import enviro firmware, this will trigger provisioning if needed
import enviro
import os


try:
# initialise enviro
enviro.startup()
Expand All @@ -42,7 +47,19 @@
if enviro.low_disk_space():
# less than 10% of diskspace left, this probably means cached results
# are not getting uploaded so warn the user and halt with an error
enviro.halt("! low disk space")

# Issue #126 to try and upload if disk space is low
# is an upload destination set?
if enviro.config.destination:
enviro.logging.error("! low disk space. Attempting to upload file(s)")

# if we have enough cached uploads...
enviro.logging.info(f"> {enviro.cached_upload_count()} cache file(s) need uploading")
if not enviro.upload_readings():
enviro.halt("! reading upload failed")
else:
# no destination so go to sleep
enviro.halt("! low disk space")

# TODO this seems to be useful to keep around?
filesystem_stats = os.statvfs(".")
Expand Down

0 comments on commit d47dd7a

Please sign in to comment.