This repository has been archived by the owner on Feb 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Old md-cloud fixes that should better go to master #97
Open
pereferrera
wants to merge
7
commits into
master
Choose a base branch
from
DEV-2292
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
05e0349
WIP
bea187e
Merge branch 'master' into DEV-2292
4759a20
Invalid session lifecycle handle
400dff6
Catch psql OperationalErrors
4b27b19
Merge branch 'master' into DEV-2292
dc15476
Merge branch 'master' into DEV-2292
c86f60f
Merge branch 'master' into DEV-2292
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
import logging | ||
|
||
from tenacity.retry import retry_if_exception_type | ||
from tenacity.retry import retry_if_exception | ||
from tenacity import retry, stop_after_attempt, wait_fixed | ||
|
||
from sqlite3 import OperationalError as Sqlite3OperationalError | ||
from sqlalchemy.exc import OperationalError | ||
|
||
from mediaire_toolbox.constants import ( | ||
RETRY_DATABASE_OP_SECONDS, | ||
|
@@ -28,11 +26,17 @@ def before_sleep_log(retry_state): | |
retry_state.outcome)) | ||
|
||
|
||
def is_operational_error(e): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to fix this in order to properly catch Psql operational errors |
||
return ( | ||
'OperationalError' in str(e) or | ||
'OperationalError' in e.__class__.__name__ | ||
) | ||
|
||
|
||
def t_db_retry(f): | ||
return retry( | ||
retry=( | ||
retry_if_exception_type(OperationalError) | ||
| retry_if_exception_type(Sqlite3OperationalError)), | ||
retry_if_exception(is_operational_error)), | ||
stop=stop_after_attempt(RETRY_DATABASE_OP_TIMES), | ||
wait=wait_fixed(RETRY_DATABASE_OP_SECONDS), | ||
before_sleep=before_sleep_log)(f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,12 +236,12 @@ def create_transaction(self, | |
@lock | ||
def get_transaction(self, id_: int) -> Transaction: | ||
try: | ||
return self._get_transaction_or_raise_exception(id_) | ||
finally: | ||
# we should always complete the lifetime of the connection, | ||
# otherwise we might run into timeout errors | ||
# (see https://docs.sqlalchemy.org/en/latest/orm/session_transaction.html) # noqa: 501 | ||
t = self._get_transaction_or_raise_exception(id_) | ||
self.session.commit() | ||
return t | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think here the lifecycle was not handled properly so I got errors (but in sqlite it doesn't matter because there are no connections) |
||
except Exception: | ||
self.session.rollback() | ||
raise | ||
|
||
def _get_transaction_or_raise_exception(self, id_: int): | ||
t = self.session.query(Transaction).get(id_) | ||
|
@@ -723,8 +723,9 @@ def get_study_metadata(self, study_id: str) -> StudiesMetadata: | |
try: | ||
return self.session.query(StudiesMetadata)\ | ||
.filter_by(study_id=study_id).first() | ||
finally: | ||
self.session.commit() | ||
except Exception: | ||
self.session.rollback() | ||
|
||
@t_db_retry | ||
def get_user_sites(self, user_id: int): # TODO -> Query[UserSite]: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines can only be executed if you instantiate the daemons in the main execution thread, but that is not the case in md_cloud_compute