Skip to content

Commit

Permalink
Add timeout for ms to do
Browse files Browse the repository at this point in the history
  • Loading branch information
dgsasha committed May 1, 2023
1 parent 6e63f5c commit 29bc9cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion po/remembrance.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: remembrance\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-05-01 17:22-0400\n"
"POT-Creation-Date: 2023-05-01 18:59-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down
30 changes: 15 additions & 15 deletions src/service/ms_to_do.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from remembrance import info
from remembrance.service.reminder import Reminder
from msal import PublicClientApplication, SerializableTokenCache
from requests import request, HTTPError, ConnectionError
from requests import request, HTTPError, ConnectionError, Timeout
from logging import getLogger
from atexit import register as atexit_register
from json import dumps, loads
Expand Down Expand Up @@ -89,9 +89,9 @@ def start_server(self, server):
def do_request(self, method, url, user_id, data = None, retry = True):
try:
if data is None:
results = request(method, f'{GRAPH}/{url}', headers={'Authorization': f'Bearer {self.tokens[user_id]}'})
results = request(method, f'{GRAPH}/{url}', headers={'Authorization': f'Bearer {self.tokens[user_id]}'}, timeout=5)
else:
results = request(method, f'{GRAPH}/{url}', data=dumps(data), headers={'Authorization': f'Bearer {self.tokens[user_id]}', 'Content-Type': 'application/json'})
results = request(method, f'{GRAPH}/{url}', data=dumps(data), headers={'Authorization': f'Bearer {self.tokens[user_id]}', 'Content-Type': 'application/json'}, timeout=5)
results.raise_for_status()
return results
except HTTPError as error:
Expand Down Expand Up @@ -120,7 +120,7 @@ def get_tokens(self):
for account in accounts:
try:
token = self.app.acquire_token_silent(SCOPES, account)['access_token']
result = request('GET', f'{GRAPH}/me', headers={'Authorization': f'Bearer {token}'})
result = request('GET', f'{GRAPH}/me', headers={'Authorization': f'Bearer {token}'}, timeout=5)
result.raise_for_status()
result = result.json()
user_id = result['id']
Expand All @@ -137,14 +137,14 @@ def get_tokens(self):
raise error
else:
logger.exception(error)
except ConnectionError as error:
except (ConnectionError, Timeout) as error:
raise error
except Exception as error:
logger.exception(error)

self.store()

except (ConnectionError, HTTPError) as error:
except (ConnectionError, HTTPError, Timeout) as error:
try:
self.users = loads(
Secret.password_lookup_sync(
Expand Down Expand Up @@ -207,7 +207,7 @@ def login(self, results):
result = self.app.acquire_token_by_auth_code_flow(self.flow, results)
token = result['access_token']
local_id = result['id_token_claims']['oid']
result = request('GET', f'{GRAPH}/me', headers={'Authorization': f'Bearer {token}'})
result = request('GET', f'{GRAPH}/me', headers={'Authorization': f'Bearer {token}'}, timeout=5)
result.raise_for_status()
result = result.json()
user_id = result['id']
Expand Down Expand Up @@ -304,7 +304,7 @@ def create_task(self, user_id, task_list, task):
else:
logger.exception(error)
raise error
except ConnectionError as error:
except (ConnectionError, Timeout) as error:
if user_id in self.tokens.keys():
self.tokens.pop(user_id)
raise error
Expand All @@ -328,7 +328,7 @@ def update_task(self, user_id, task_list, task_id, task):
else:
logger.exception(error)
raise error
except ConnectionError as error:
except (ConnectionError, Timeout) as error:
if user_id in self.tokens.keys():
self.tokens.pop(user_id)
raise error
Expand All @@ -349,7 +349,7 @@ def remove_task(self, user_id, task_list, task_id):
else:
logger.exception(error)
raise error
except ConnectionError as error:
except (ConnectionError, Timeout) as error:
raise error
except Exception as error:
logger.exception(error)
Expand All @@ -372,7 +372,7 @@ def create_list(self, user_id, list_name):
else:
logger.exception(error)
raise error
except ConnectionError as error:
except (ConnectionError, Timeout) as error:
if user_id in self.tokens.keys():
self.tokens.pop(user_id)
raise error
Expand All @@ -396,7 +396,7 @@ def update_list(self, user_id, ms_id, list_name):
else:
logger.exception(error)
raise error
except ConnectionError as error:
except (ConnectionError, Timeout) as error:
if user_id in self.tokens.keys():
self.tokens.pop(user_id)
raise error
Expand All @@ -419,7 +419,7 @@ def delete_list(self, user_id, ms_id):
else:
logger.exception(error)
raise error
except ConnectionError as error:
except (ConnectionError, Timeout) as error:
if user_id in self.tokens.keys():
self.tokens.pop(user_id)
raise error
Expand Down Expand Up @@ -493,7 +493,7 @@ def get_lists(self, removed_list_ids, old_lists, synced_ids, only_user_id = None
else:
logger.exception(error)
not_synced.append(user_id)
except ConnectionError:
except (ConnectionError, Timeout):
not_synced.append(user_id)
self.tokens.pop(user_id)
except Exception as error:
Expand All @@ -519,7 +519,7 @@ def get_tasks(self, list_id, user_id):
else:
logger.exception(error)
raise error
except ConnectionError as error:
except (ConnectionError, Timeout) as error:
if user_id in self.tokens.keys():
self.tokens.pop(user_id)
raise error
Expand Down

0 comments on commit 29bc9cf

Please sign in to comment.