Skip to content
This repository has been archived by the owner on Jan 3, 2019. It is now read-only.

Creating a restart function for storage classes to fix broken database connections #196

Merged
merged 3 commits into from
Feb 18, 2015

Conversation

rich-hart
Copy link
Contributor

Fix #47

except storage.Error:
logger.exception('Storage failed to restart')
finally:
raise httpexceptions.HTTPServiceUnavailable()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious if there is anyway to make this section more concise without having to use these nested try / except statements

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know a better way to do this.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.22%) to 97.32% when pulling f9d4ff3 on database_restart into 737a36c on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.22%) to 97.32% when pulling f9d4ff3 on database_restart into 737a36c on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.22%) to 97.32% when pulling bf4d85e on database_restart into 737a36c on master.

@rich-hart
Copy link
Contributor Author

Since were adding a coveralls configuration file I think that it would be best to leave this pull request as two separate commits since the commits address two distinct issues.

@@ -61,6 +61,7 @@ class PostgresqlStorage(BaseStorage):
def __init__(self, db_connection_string=None):
#initialize db
self.conn = psycopg2.connect(db_connection_string)
self.db_connection_string = db_connection_string
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding a variable to store the db_connection string needed to restart the database when a connection is broken or lost.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Come to think about it, shouldn't your note be comment in the code?

@rich-hart rich-hart force-pushed the database_restart branch 2 times, most recently from fa6bf17 to 333bcf1 Compare February 17, 2015 22:32
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 333bcf1 on database_restart into * on master*.

# Have to re-enable the standard pragma
pragma: no cover

# Don't complain if tests don't hit defensive assertion code:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this comment is relevant

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling b06530a on database_restart into * on master*.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 8bca86d on database_restart into * on master*.

@mmulich
Copy link
Member

mmulich commented Feb 18, 2015

Why is the storage_managment function in the views module? I know it wasn't put in there during this pull request. But it is definitely in the wrong module.

Otherwise, I think this is ready to roll.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 1b2446a on database_restart into * on master*.

@mmulich
Copy link
Member

mmulich commented Feb 18, 2015

I adjusted the .coveragerc file. The coverage run has now been scoped to the cnxauthoring package (Note, coveralls does this by default). The report has also been limited to include all the modules and omit the tests and scripts.

mmulich added a commit that referenced this pull request Feb 18, 2015
Creating a restart function for storage classes to fix broken database connections
@mmulich mmulich merged commit 768170b into master Feb 18, 2015
@mmulich mmulich deleted the database_restart branch February 18, 2015 19:50
@karenc
Copy link
Member

karenc commented Feb 18, 2015

Oh but may be it's good to include the tests in the coverage. Just in case tests got skipped because we have some indentation error, or because of copy and paste error (See openstax/cnx-archive@09fdd6a).

@mmulich
Copy link
Member

mmulich commented Feb 18, 2015

@karenc That's a good point, but it also artificially inflates the coverage (i.e. 92% vs 96%). I'll pull it out in a followup pull request. Unfortunately, you comment came in just after I pushed the button.

@rich-hart
Copy link
Contributor Author

@pumazi the storage_managment function was added to views.py when 6c7025d was committed. It was used to clean up the 'persist' and 'abort' functions that were scattered throughout the views module and to also allow for a consistent way of sending an httpexceptions to the user. I left the storage_managment in views because that where the persist and abort functions were currently being used. Also, as karen pointed out when I was working on it, generating storage failure messages and passing them to the user is essentially a responsibility for views. I see your point though because I was originally thinking the same thing but does my explanation make sense? Let me know if you still think moving somewhere else would be a better practice

@mmulich
Copy link
Member

mmulich commented Feb 18, 2015

I believe it would be better to make the BaseStorage class a context manager, then this second function wouldn't be needed. Simply import storage and use it. But that's another story altogether...

For now, I'd say it belongs in the cnxauthoring.storage.main and importable from cnxauthoring.storage.

@rich-hart
Copy link
Contributor Author

ok! I made an issue #200 suggesting that we make a context manager in the Base storage class. I'll also make a pull request to refactor the storage_management decorator.

@mmulich
Copy link
Member

mmulich commented Feb 18, 2015

I may have misunderstood this somewhat. But we'll see what happens.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

not robust to db bounce
5 participants