Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add requests timeout #131

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions monday/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
"API-Version": "2023-10"
}

DEFAULT_TIMEOUT = 60

class MondayClient:
def __init__(self, token, headers=None):
def __init__(self, token, headers=None, timeout=DEFAULT_TIMEOUT):
"""
:param token: API token for the new :class:`BaseResource` object.
:param headers: (optional) headers for the new :class:`BaseResource` object.
Expand All @@ -25,18 +26,18 @@ def __init__(self, token, headers=None):
if not headers:
headers = _DEFAULT_HEADERS.copy()

self.custom = CustomResource(token=token, headers=headers)
self.items = ItemResource(token=token, headers=headers)
self.columns = ColumnsResource(token=token, headers=headers)
self.updates = UpdateResource(token=token, headers=headers)
self.tags = TagResource(token=token, headers=headers)
self.boards = BoardResource(token=token, headers=headers)
self.users = UserResource(token=token, headers=headers)
self.groups = GroupResource(token=token, headers=headers)
self.complexity = ComplexityResource(token=token, headers=headers)
self.workspaces = WorkspaceResource(token=token, headers=headers)
self.notifications = NotificationResource(token=token, headers=headers)
self.me = MeResource(token=token, headers=headers)
self.custom = CustomResource(token=token, headers=headers, timeout=timeout)
self.items = ItemResource(token=token, headers=headers, timeout=timeout)
self.columns = ColumnsResource(token=token, headers=headers, timeout=timeout)
self.updates = UpdateResource(token=token, headers=headers, timeout=timeout)
self.tags = TagResource(token=token, headers=headers, timeout=timeout)
self.boards = BoardResource(token=token, headers=headers, timeout=timeout)
self.users = UserResource(token=token, headers=headers, timeout=timeout)
self.groups = GroupResource(token=token, headers=headers, timeout=timeout)
self.complexity = ComplexityResource(token=token, headers=headers, timeout=timeout)
self.workspaces = WorkspaceResource(token=token, headers=headers, timeout=timeout)
self.notifications = NotificationResource(token=token, headers=headers, timeout=timeout)
self.me = MeResource(token=token, headers=headers, timeout=timeout)

def __str__(self):
return f'MondayClient {__version__}'
Expand Down
6 changes: 4 additions & 2 deletions monday/graphqlclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

TOKEN_HEADER = 'Authorization'

DEFAULT_TIMEOUT = 60

class GraphQLClient:
def __init__(self, endpoint):
def __init__(self, endpoint, timeout=DEFAULT_TIMEOUT):
self.endpoint = endpoint
self.timeout = timeout
self.token = None
self.headers = {}

Expand Down Expand Up @@ -43,7 +45,7 @@ def _send(self, query, variables):
]

try:
response = requests.request("POST", self.endpoint, headers=headers, data=payload, files=files)
response = requests.request("POST", self.endpoint, headers=headers, data=payload, files=files, timeout=self.timeout)
response.raise_for_status()
response_data = response.json()
self._throw_on_error(response_data)
Expand Down
6 changes: 3 additions & 3 deletions monday/resources/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@


class BaseResource:
def __init__(self, token, headers):
def __init__(self, token, headers, timeout):
self._token = token
self.client = GraphQLClient(_URLS['prod'])
self.file_upload_client = GraphQLClient(_URLS['file'])
self.client = GraphQLClient(_URLS['prod'], timeout=timeout)
self.file_upload_client = GraphQLClient(_URLS['file'], timeout=timeout)
self.client.inject_token(token)
self.client.inject_headers(headers)
self.file_upload_client.inject_token(token)
Expand Down
Loading