Skip to content
Merged
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
5 changes: 4 additions & 1 deletion api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,7 @@ VALIDATOR_MAX_EVALUATION_RUN_LOG_SIZE_BYTES=500000 # 500 KB


MINER_AGENT_UPLOAD_RATE_LIMIT_SECONDS=86400 # 24 hours
NUM_EVALS_PER_AGENT=3
NUM_EVALS_PER_AGENT=3

SHOULD_RUN_LOOPS=False
FETCH_METAGRAPH_INTERVAL_SECONDS=120
12 changes: 12 additions & 0 deletions api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@
logger.fatal("NUM_EVALS_PER_AGENT is not set in .env")
NUM_EVALS_PER_AGENT = int(NUM_EVALS_PER_AGENT)

SHOULD_RUN_LOOPS = os.getenv("SHOULD_RUN_LOOPS")
if not SHOULD_RUN_LOOPS:
logger.fatal("SHOULD_RUN_LOOPS is not set in .env")
SHOULD_RUN_LOOPS = SHOULD_RUN_LOOPS.lower() == "true"

FETCH_METAGRAPH_INTERVAL_SECONDS = os.getenv("FETCH_METAGRAPH_INTERVAL_SECONDS")
if not FETCH_METAGRAPH_INTERVAL_SECONDS:
default_fetch_metagraph_interval_seconds = 120
logger.warning(f"FETCH_METAGRAPH_INTERVAL_SECONDS is not set in .env, using default of {default_fetch_metagraph_interval_seconds} seconds")
FETCH_METAGRAPH_INTERVAL_SECONDS = default_fetch_metagraph_interval_seconds
else:
FETCH_METAGRAPH_INTERVAL_SECONDS = int(FETCH_METAGRAPH_INTERVAL_SECONDS)


logger.info("=== API Configuration ===")
Expand Down
15 changes: 15 additions & 0 deletions api/loops/fetch_metagraph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import asyncio
import api.config as config
import utils.logger as logger

from utils.bittensor import fetch_and_save_registered_hotkeys



async def fetch_metagraph_loop():
logger.info("Starting fetch metagraph loop...")

while True:
await fetch_and_save_registered_hotkeys()

await asyncio.sleep(config.FETCH_METAGRAPH_INTERVAL_SECONDS)
8 changes: 6 additions & 2 deletions api/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from fastapi.middleware.cors import CORSMiddleware
import uvicorn

from api.loops.fetch_metagraph import fetch_metagraph_loop
from api.loops.validator_heartbeat_timeout import validator_heartbeat_timeout_loop


Expand Down Expand Up @@ -56,8 +57,11 @@ async def lifespan(app: FastAPI):
secret_access_key=config.AWS_SECRET_ACCESS_KEY
)

# Loop setup
asyncio.create_task(validator_heartbeat_timeout_loop())
# Loops
if config.SHOULD_RUN_LOOPS: # validator loops; TODO: rename env var
asyncio.create_task(validator_heartbeat_timeout_loop())

asyncio.create_task(fetch_metagraph_loop())



Expand Down
2 changes: 1 addition & 1 deletion ridges.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import time

console = Console()
DEFAULT_API_BASE_URL = "https://platform-v2.ridges.ai"
DEFAULT_API_BASE_URL = "https://agent-upload.ridges.ai"

load_dotenv(".env")

Expand Down