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

DB access consistency #408

Merged
merged 6 commits into from
Jan 23, 2018
Merged

DB access consistency #408

merged 6 commits into from
Jan 23, 2018

Conversation

wtgee
Copy link
Member

@wtgee wtgee commented Jan 22, 2018

In preparation for #120, this is brining some consistency to the access
of DB items so it will be easier to decouple from mongo if needed.

In preparation for panoptes#120, this is brining some consistency to the access
of DB items so it will be easier to decouple from mongo if needed.
@wtgee wtgee requested a review from jamessynge January 22, 2018 05:41
@codecov
Copy link

codecov bot commented Jan 22, 2018

Codecov Report

Merging #408 into develop will increase coverage by 0.1%.
The diff coverage is 84.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##           develop     #408     +/-   ##
==========================================
+ Coverage    69.05%   69.15%   +0.1%     
==========================================
  Files           60       60             
  Lines         4757     4773     +16     
  Branches       656      659      +3     
==========================================
+ Hits          3285     3301     +16     
+ Misses        1297     1295      -2     
- Partials       175      177      +2
Impacted Files Coverage Δ
pocs/core.py 79.83% <100%> (ø) ⬆️
pocs/base.py 96.96% <100%> (ø) ⬆️
pocs/utils/database.py 91.93% <83.33%> (+2.8%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 220da77...8c897bf. Read the comment docs.

Copy link
Contributor

@jamessynge jamessynge left a comment

Choose a reason for hiding this comment

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

Seems like a good move, thanks.

@@ -44,15 +43,19 @@ class PanSensorShell(cmd.Cmd):
def do_status(self, *arg):
""" Get the entire system status and print it pretty like! """
if self._keep_looping:
console.color_print("{:>12s}: ".format('Loop Timer'), "default", "active", "lightgreen")
console.color_print("{:>12s}: ".format('Loop Timer'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nothing changed except the wrapping, right?
If so, why was this changed, as it was 100 chars wide, which I thought we'd agreed on.

Copy link
Member Author

@wtgee wtgee Jan 22, 2018

Choose a reason for hiding this comment

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

100 char limit means it wraps at 99, which this line is. From the pep8:

For code maintained exclusively or primarily by a team that can reach agreement on this issue, it is okay to increase the nominal line length from 80 to 100 characters (effectively increasing the maximum length to 99 characters)

@@ -78,16 +78,18 @@ def __init__(self, db='panoptes', host='localhost', port=27017, connect=False):
setattr(self, collection, getattr(db_handle, collection))

def insert_current(self, collection, obj, include_collection=True):
"""Insert an object into both the `current` collection and the collection provided
"""Insert an object into both the `current` collection and the collection provided.
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding the periods! 😉

_id = None
try:
# If `data` key is present we assume it has "metadata" for object
if 'data' in obj:
Copy link
Contributor

Choose a reason for hiding this comment

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

if isinstance(obj, dict) and 'data' in obj:


_id = None
try:
# If `data` key is present we assume it has "metadata" for object
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this mean: it has "metadata" for object
What does it refer to there?
And what is the metadata?


# Insert record into db
col = getattr(self, collection)
_id = col.insert_one(obj).inserted_id
except Exception as e:
warn("Problem inserting object into collection: {}".format(e))
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add an additional message with the obj to be inserted?
And note that this is not written to the log file, which would really be useful!

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed this so now we have a logger in PanMongo and warnings will go to appropriate place.

rec = {'test': 'insert'}
db.insert('config', rec)

record = db.config.find({'data.test': {'$exists': 1}})
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems very mongo specific. Are you not attempting to address that ... yet?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct. I was thinking of actually renaming to test_mongo.py, which could be part of this PR. Actually addressing anything non-mongo is for another PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed to test_panmongo.py for now.

obj (dict or str): Object to be inserted.

Returns:
str: Mongo object ID of record in `collection`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Error behavior?

Copy link
Member Author

Choose a reason for hiding this comment

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

There currently isn't any error that is raised as we just catch the exceptions and give a warning. Not sure if that is ideal or not but it does allow operations to continue.

* Add a logger to PanMongo
* Some docstrings
* Rename testing file to be mongo specific
@wtgee wtgee merged commit 370116a into panoptes:develop Jan 23, 2018
@wtgee wtgee deleted the consistent-db-calls branch January 23, 2018 02:09
@wtgee wtgee mentioned this pull request Jan 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants