浏览代码

Fix/add retry mechanism to billing service request handling (#12006)

Signed-off-by: -LAN- <laipz8200@outlook.com>
tags/0.14.2
-LAN- 10 个月前
父节点
当前提交
425cc1ea85
没有帐户链接到提交者的电子邮件
共有 1 个文件被更改,包括 9 次插入2 次删除
  1. 9
    2
      api/services/billing_service.py

+ 9
- 2
api/services/billing_service.py 查看文件

import os import os


import requests
import httpx
from tenacity import retry, retry_if_not_exception_type, stop_before_delay, wait_fixed


from extensions.ext_database import db from extensions.ext_database import db
from models.account import TenantAccountJoin, TenantAccountRole from models.account import TenantAccountJoin, TenantAccountRole
return cls._send_request("GET", "/invoices", params=params) return cls._send_request("GET", "/invoices", params=params)


@classmethod @classmethod
@retry(
wait=wait_fixed(2),
stop=stop_before_delay(10),
retry=retry_if_not_exception_type(httpx.RequestError),
reraise=True,
)
def _send_request(cls, method, endpoint, json=None, params=None): def _send_request(cls, method, endpoint, json=None, params=None):
headers = {"Content-Type": "application/json", "Billing-Api-Secret-Key": cls.secret_key} headers = {"Content-Type": "application/json", "Billing-Api-Secret-Key": cls.secret_key}


url = f"{cls.base_url}{endpoint}" url = f"{cls.base_url}{endpoint}"
response = requests.request(method, url, json=json, params=params, headers=headers)
response = httpx.request(method, url, json=json, params=params, headers=headers)


return response.json() return response.json()



正在加载...
取消
保存