Some checks failed
Pre-commit / run (ubuntu-latest) (push) Has been cancelled
Deploy Sphinx documentation to Pages / build_en (ubuntu-latest, 3.10) (push) Has been cancelled
Deploy Sphinx documentation to Pages / build_zh (ubuntu-latest, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (macos-15, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (macos-15, 3.11) (push) Has been cancelled
Python Unittest Coverage / test (macos-15, 3.12) (push) Has been cancelled
Python Unittest Coverage / test (ubuntu-latest, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (ubuntu-latest, 3.11) (push) Has been cancelled
Python Unittest Coverage / test (ubuntu-latest, 3.12) (push) Has been cancelled
Python Unittest Coverage / test (windows-latest, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (windows-latest, 3.11) (push) Has been cancelled
Python Unittest Coverage / test (windows-latest, 3.12) (push) Has been cancelled
27 lines
751 B
Python
27 lines
751 B
Python
from __future__ import annotations
|
|
|
|
import asyncio
|
|
from typing import Any
|
|
|
|
import requests
|
|
|
|
from .config import TIANWANG_CALLBACK_URL
|
|
|
|
|
|
async def post_tianwang_callback(event: str, data: dict[str, Any], extra: dict[str, Any] | None = None, timeout_s: int = 5) -> tuple[bool, int, str]:
|
|
payload = {
|
|
'event': event,
|
|
'data': data,
|
|
'extra': extra or {},
|
|
}
|
|
|
|
def _post() -> tuple[bool, int, str]:
|
|
try:
|
|
resp = requests.post(TIANWANG_CALLBACK_URL, json=payload, timeout=timeout_s)
|
|
ok = 200 <= resp.status_code < 300
|
|
return ok, resp.status_code, (resp.text or '')[:300]
|
|
except Exception as e:
|
|
return False, 0, str(e)
|
|
|
|
return await asyncio.to_thread(_post)
|