Ejemplo n.º 1
0
def deleter_thread(exit_event):
    while not exit_event.is_set():
        available_bytes = get_available_bytes()

        if available_bytes is not None and available_bytes < (5 * 1024 * 1024 *
                                                              1024):
            # remove the earliest directory we can
            dirs = listdir_by_creation(ROOT)
            for delete_dir in dirs:
                delete_path = os.path.join(ROOT, delete_dir)

                if any(
                        name.endswith(".lock")
                        for name in os.listdir(delete_path)):
                    continue

                try:
                    cloudlog.info("deleting %s" % delete_path)
                    shutil.rmtree(delete_path)
                    break
                except OSError:
                    cloudlog.exception("issue deleting %s" % delete_path)
            exit_event.wait(.1)
        else:
            exit_event.wait(30)
Ejemplo n.º 2
0
def deleter_thread(exit_event):
    while not exit_event.is_set():
        out_of_bytes = get_available_bytes(default=MIN_BYTES + 1) < MIN_BYTES
        out_of_percent = get_available_percent(default=MIN_PERCENT +
                                               1) < MIN_PERCENT

        if out_of_percent or out_of_bytes:
            # remove the earliest directory we can
            dirs = sorted(listdir_by_creation(ROOT),
                          key=lambda x: x in DELETE_LAST)
            for delete_dir in dirs:
                delete_path = os.path.join(ROOT, delete_dir)

                if any(
                        name.endswith(".lock")
                        for name in os.listdir(delete_path)):
                    continue

                try:
                    cloudlog.info(f"deleting {delete_path}")
                    if os.path.isfile(delete_path):
                        os.remove(delete_path)
                    else:
                        shutil.rmtree(delete_path)
                    break
                except OSError:
                    cloudlog.exception(f"issue deleting {delete_path}")
            exit_event.wait(.1)
        else:
            exit_event.wait(30)
Ejemplo n.º 3
0
def deleter_thread(exit_event):
    while not exit_event.is_set():

        for delete_path in get_dirs_xdays_ago(ROOT, xdays=3):
            cloudlog.info("deleting %s" % delete_path)
            shutil.rmtree(delete_path, ignore_errors=True)

        # deleting rlogs
        available_bytes = get_available_bytes()
        if available_bytes is not None and available_bytes < (8 * 1024 * 1024 *
                                                              1024):
            # remove the earliest directory we can
            dirs = listdir_by_creation(ROOT) if os.path.isdir(ROOT) else []
            for delete_dir in dirs:
                delete_path = os.path.join(ROOT, delete_dir)

                if any(
                        name.endswith(".lock")
                        for name in os.listdir(delete_path)):
                    continue

                try:
                    cloudlog.info("deleting %s" % delete_path)
                    shutil.rmtree(delete_path)
                    break
                except OSError:
                    cloudlog.exception("issue deleting %s" % delete_path)
            exit_event.wait(.1)

        # deleting dashcam
        if available_bytes is not None and available_bytes < (5 * 1024 * 1024 *
                                                              1024):
            dirs = listdir_by_creation(DASHCAM_ROOT) if os.path.isdir(
                DASHCAM_ROOT) else []
            for delete_dir in dirs:
                delete_path = os.path.join(DASHCAM_ROOT, delete_dir)
                try:
                    cloudlog.info("deleting %s" % delete_path)
                    os.remove(delete_path)
                    break
                except OSError:
                    cloudlog.exception("issue deleting %s" % delete_path)
            exit_event.wait(.1)

        # wait 30s
        if available_bytes >= (8 * 1024 * 1024 * 1024):
            exit_event.wait(30)