Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions utils/temp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"""Utilities for creating temporary directories."""
import utils.logger as logger

from pathlib import Path
import shutil
import tempfile
import time




Expand All @@ -14,5 +18,16 @@ def create_temp_dir():

def delete_temp_dir(temp_dir: str):
"""Delete a temporary directory."""

shutil.rmtree(temp_dir, ignore_errors=True)
shutil.rmtree(temp_dir, ignore_errors=True)



def clean_tmp(tmp_clean_age_seconds: int = 3600):
for path in Path(tempfile.gettempdir()).glob("tmp*"):
now = time.time()
modified_time = path.stat().st_mtime
age = now - modified_time

if age > tmp_clean_age_seconds:
logger.debug(f"Deleting {path}")
shutil.rmtree(path, ignore_errors=True)
5 changes: 5 additions & 0 deletions validator/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ INCLUDE_SOLUTIONS=False



CLEAN_TMP_AGE_SECONDS=3600
CLEAN_TMP_INTERVAL_SECONDS=3600



UPDATE_AUTOMATICALLY=True
15 changes: 15 additions & 0 deletions validator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@



CLEAN_TMP_AGE_SECONDS = os.getenv("CLEAN_TMP_AGE_SECONDS")
if not CLEAN_TMP_AGE_SECONDS:
CLEAN_TMP_AGE_SECONDS = 3600
CLEAN_TMP_AGE_SECONDS = int(CLEAN_TMP_AGE_SECONDS)

CLEAN_TMP_INTERVAL_SECONDS = os.getenv("CLEAN_TMP_INTERVAL_SECONDS")
if not CLEAN_TMP_INTERVAL_SECONDS:
CLEAN_TMP_INTERVAL_SECONDS = 3600
CLEAN_TMP_INTERVAL_SECONDS = int(CLEAN_TMP_INTERVAL_SECONDS)



# Print out the configuration
logger.info("=== Validator Configuration ===")
logger.info(f"Network ID: {NETUID}")
Expand All @@ -163,6 +175,9 @@
logger.info(f"Set Weights Interval: {SET_WEIGHTS_INTERVAL_SECONDS} second(s)")
logger.info(f"Request Evaluation Interval: {REQUEST_EVALUATION_INTERVAL_SECONDS} second(s)")
logger.info("-------------------------------")
logger.info(f"Clean tmp age: {CLEAN_TMP_AGE_SECONDS} second(s)")
logger.info(f"Clean tmp interval: {CLEAN_TMP_INTERVAL_SECONDS} second(s)")
logger.info("-------------------------------")
if SIMULATE_EVALUATION_RUNS:
logger.warning("Simulating Evaluation Runs!")
else:
Expand Down
7 changes: 6 additions & 1 deletion validator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ async def set_weights_loop():

await asyncio.sleep(config.SET_WEIGHTS_INTERVAL_SECONDS)


async def clean_tmp_loop():
logger.info("Starting clean tmp loop...")
while True:
clean_tmp(config.CLEAN_TMP_AGE_SECONDS)
await asyncio.sleep(config.CLEAN_TMP_INTERVAL_SECONDS)

# Sends an update-evaluation-run request to the Ridges platform. The extra
# parameter is for fields that are not sent in all requests, such as agent_logs
Expand Down Expand Up @@ -361,6 +365,7 @@ async def main():

# Start the send heartbeat loop
asyncio.create_task(send_heartbeat_loop())
asyncio.create_task(clean_tmp_loop())

if config.MODE == "validator":
# Start the set weights loop
Expand Down