mirror of
https://github.com/flobz/psa_car_controller.git
synced 2026-08-21 17:06:18 +00:00
feat: add timeout
This commit is contained in:
committed by
Florian BEZANNIER
parent
5b2cfe993c
commit
643b537952
@@ -15,7 +15,7 @@ from psa_car_controller.psa.constants import INPROGRESS, DEFAULT_PRECONDITIONING
|
||||
DELAYED_CHARGE, REMOTE_URL
|
||||
from psa_car_controller.psa.mqtt_request import MQTTRequest
|
||||
from psa_car_controller.psa.oauth import OpenIdCredentialManager
|
||||
from psa_car_controller.common.utils import RateLimitException, rate_limit, parse_hour
|
||||
from psa_car_controller.common.utils import RateLimitException, rate_limit, parse_hour, TIMEOUT_IN_S
|
||||
from psa_car_controller.psa.otp.otp import ConfigException, save_otp, load_otp
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -130,6 +130,7 @@ class RemoteClient:
|
||||
self.mqtt_client.disconnect()
|
||||
if self.update_thread:
|
||||
self.update_thread.cancel()
|
||||
self.update_thread.join(timeout=TIMEOUT_IN_S)
|
||||
|
||||
def __keep_mqtt(self): # avoid token expiration
|
||||
timeout = 3600 * 24 # 1 day
|
||||
|
||||
@@ -10,7 +10,7 @@ from typing import Optional
|
||||
from oauth2_client.credentials_manager import CredentialManager, ServiceInformation
|
||||
from requests import Response, RequestException
|
||||
|
||||
from psa_car_controller.common.utils import rate_limit
|
||||
from psa_car_controller.common.utils import rate_limit, TIMEOUT_IN_S
|
||||
from psa_car_controller.psa import connected_car_api
|
||||
from psa_car_controller.psa.connected_car_api import ApiClient
|
||||
from psa_car_controller.psa.connected_car_api.rest import ApiException
|
||||
@@ -84,6 +84,11 @@ class OpenIdCredentialManager(CredentialManager):
|
||||
logger.error("Can't refresh token %s", e)
|
||||
return False
|
||||
|
||||
def request(self, method, url, **kwargs): # pylint: disable=W0221
|
||||
if "timeout" not in kwargs:
|
||||
kwargs["timeout"] = TIMEOUT_IN_S
|
||||
return super().request(method, url, **kwargs)
|
||||
|
||||
|
||||
class Oauth2PSACCApiConfig(connected_car_api.Configuration):
|
||||
def __init__(self):
|
||||
@@ -102,6 +107,7 @@ class OauthAPIClient(ApiClient):
|
||||
response_type=None, auth_settings=None, async_req=None,
|
||||
_return_http_data_only=None, collection_formats=None,
|
||||
_preload_content=True, _request_timeout=None):
|
||||
_request_timeout = _request_timeout or TIMEOUT_IN_S
|
||||
for _ in range(0, 2):
|
||||
try:
|
||||
if not async_req:
|
||||
|
||||
@@ -6,7 +6,7 @@ from os import path
|
||||
import requests
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
TIMEOUT_IN_S = 10
|
||||
TIMEOUT_IN_S = 20
|
||||
|
||||
|
||||
def get_github_sha_from_file(user, repo, directory, filename):
|
||||
|
||||
Reference in New Issue
Block a user