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
3 changes: 3 additions & 0 deletions utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Config(TypedDict):
front_auth: str | None
floatie_auth: str | None
debug: bool
randomize_worker_names: bool


config: Config = yaml.safe_load(open("config.yaml" if not in_test() else "tests/test_config.yaml"))
Expand All @@ -56,3 +57,5 @@ class Config(TypedDict):
config["proxy_url"] = None
if "proxy_token" not in config:
config["proxy_token"] = None
if "randomize_worker_names" not in config:
config["randomize_worker_names"] = True
6 changes: 5 additions & 1 deletion utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
from socket import gethostname
import random

from .config import config


def random_hex(length: int) -> str:
byte_count = math.ceil(length / 2)
return random.randbytes(byte_count).hex()[:length]


def generate_worker_name() -> str:
return f"{gethostname()}-{random_hex(4)}"
if config["randomize_worker_names"]:
return f"{gethostname()}-{random_hex(4)}"
return gethostname()
Loading