Skip to content

Commit

Permalink
Fix/add retry mechanism to billing service request handling (#12006)
Browse files Browse the repository at this point in the history
Signed-off-by: -LAN- <[email protected]>
  • Loading branch information
laipz8200 authored Dec 23, 2024
1 parent 2bf33c4 commit 425cc1e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions api/services/billing_service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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 models.account import TenantAccountJoin, TenantAccountRole
Expand Down Expand Up @@ -39,11 +40,17 @@ def get_invoices(cls, prefilled_email: str = "", tenant_id: str = ""):
return cls._send_request("GET", "/invoices", params=params)

@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):
headers = {"Content-Type": "application/json", "Billing-Api-Secret-Key": cls.secret_key}

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()

Expand Down

0 comments on commit 425cc1e

Please sign in to comment.