INNER CODE UNIT · Python
register_with_master
ChrispyBacon-dev/DockFlare · dockflare-agent/app/main.py:361
def register_with_master():
"""
Registers the agent with the DockFlare Master instance and retrieves an agent ID.
"""
global AGENT_ID, last_successful_master_contact
if not MASTER_URL or not API_KEY:
logging.error("Error: DOCKFLARE_MASTER_URL and DOCKFLARE_API_KEY must be set.")
return False
endpoint = f"{MASTER_URL}/api/v2/agents/register"
while True:
logging.info(f"Attempting to register with master at {endpoint}")
try:
headers = get_headers()
custom_display_name = os.getenv("AGENT_DISPLAY_NAME", "").strip()
default_display_name = f"agent-{AGENT_ID[:8]}" if AGENT_ID else "dockflare-agent"
payload = {
"display_name": custom_display_name or default_display_name,