Skip to content

Commit

Permalink
Move timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
ifigotin committed Jul 23, 2020
1 parent 4e07647 commit 2259a07
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
3 changes: 2 additions & 1 deletion patches/kaggle_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

class KaggleDatasets:
GET_GCS_PATH_ENDPOINT = '/requests/CopyDatasetVersionToKnownGcsBucketRequest'
TIMEOUT_SECS = 600

# Integration types for GCS
AUTO_ML = 1
Expand All @@ -20,5 +21,5 @@ def get_gcs_path(self, dataset_dir: str = None) -> str:
'MountSlug': dataset_dir,
'IntegrationType': integration_type,
}
result = self.web_client.make_post_request(data, self.GET_GCS_PATH_ENDPOINT)
result = self.web_client.make_post_request(data, self.GET_GCS_PATH_ENDPOINT, self.TIMEOUT_SECS)
return result['destinationBucket']
5 changes: 4 additions & 1 deletion patches/kaggle_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
from enum import Enum, unique
from typing import Optional, Tuple
from kaggle_web_client import KaggleWebClient
from kaggle_web_client import (CredentialError, BackendError, ValidationError)
from kaggle_web_client import (CredentialError, BackendError)

class ValidationError(Exception):
pass

class NotFoundError(Exception):
pass
Expand Down
8 changes: 2 additions & 6 deletions patches/kaggle_web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ class BackendError(Exception):
pass


class ValidationError(Exception):
pass

class KaggleWebClient:
TIMEOUT_SECS = 600

def __init__(self):
url_base_override = os.getenv(_KAGGLE_URL_BASE_ENV_VAR_NAME)
Expand All @@ -38,14 +34,14 @@ def __init__(self):
'X-Kaggle-Authorization': f'Bearer {self.jwt_token}',
}

def make_post_request(self, data: dict, endpoint: str) -> dict:
def make_post_request(self, data: dict, endpoint: str, timeout: int = TIMEOUT_SECS) -> dict:
url = f'{self.url_base}{endpoint}'
request_body = dict(data)
request_body['JWE'] = self.jwt_token
req = urllib.request.Request(url, headers=self.headers, data=bytes(
json.dumps(request_body), encoding="utf-8"))
try:
with urllib.request.urlopen(req, timeout=self.TIMEOUT_SECS) as response:
with urllib.request.urlopen(req, timeout=timeout) as response:
response_json = json.loads(response.read())
if not response_json.get('wasSuccessful') or 'result' not in response_json:
raise BackendError(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from kaggle_web_client import (KaggleWebClient,
_KAGGLE_URL_BASE_ENV_VAR_NAME,
_KAGGLE_USER_SECRETS_TOKEN_ENV_VAR_NAME,
CredentialError, BackendError, ValidationError)
CredentialError, BackendError)
from kaggle_datasets import KaggleDatasets, _KAGGLE_TPU_NAME_ENV_VAR_NAME

_TEST_JWT = 'test-secrets-key'
Expand Down
4 changes: 2 additions & 2 deletions tests/test_user_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from google.auth.exceptions import DefaultCredentialsError
from google.cloud import bigquery
from kaggle_secrets import (GcpTarget, UserSecretsClient,
NotFoundError)
NotFoundError, ValidationError)
from kaggle_web_client import (_KAGGLE_URL_BASE_ENV_VAR_NAME,
_KAGGLE_USER_SECRETS_TOKEN_ENV_VAR_NAME,
CredentialError, BackendError, ValidationError)
CredentialError, BackendError)

_TEST_JWT = 'test-secrets-key'

Expand Down

0 comments on commit 2259a07

Please sign in to comment.