INNER CODE UNIT · Python

_safe_response_code

ChrispyBacon-dev/DockFlare · dockflare-agent/app/main.py:408

def _safe_response_code(response):
    try:
        data = response.json()
        return str(data.get("code") or "unknown")[:64]
    except (ValueError, AttributeError):
        return "invalid_response"


def _post_agent_payload(payload):
    global last_successful_master_contact
    endpoint = f"{MASTER_URL}/api/v2/agents/{AGENT_ID}/events"
    for attempt in range(3):
        try:
            response = requests.post(endpoint, json=payload, headers=get_headers(), timeout=15)
            code = _safe_response_code(response)
            accepted_code = code in {"accepted", "accepted_noop", "duplicate_sequence", "inventory_incomplete"}
            if response.status_code in (200, 202) and (accepted_code or PROTOCOL_VERSION == 1):
                last_successful_master_contact = datetime.now(timezone.utc)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…