-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from briehl/develop
Switch over to MongoDB
- Loading branch information
Showing
17 changed files
with
260 additions
and
88 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,6 @@ python: | |
- 3.6 | ||
services: | ||
- docker | ||
# env: | ||
# global: | ||
|
||
before_install: | ||
- sudo apt-get -qq update | ||
|
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,15 +1,23 @@ | ||
[feeds] | ||
# Redis info | ||
redis-host=localhost | ||
redis-port=6379 | ||
redis-user= | ||
redis-pw= | ||
|
||
# MongoDB Info | ||
mongo-host= | ||
mongo-db= | ||
mongo-user= | ||
mongo-pw= | ||
# DB info | ||
# db-engine - allowed values = redis, mongodb. Others will raise an error on startup. | ||
db-engine=mongodb | ||
|
||
# db-name - name of the database to use. default = "feeds". | ||
db-name=feeds | ||
|
||
# Other db info. The usual - host, port, user, and password. You know the drill. | ||
db-host=localhost | ||
db-port=6379 | ||
db-user= | ||
db-pw= | ||
|
||
auth-url=https://ci.kbase.us/services/auth | ||
admins=wjriehl,scanon,kkeller | ||
|
||
# admins are allowed to use their auth tokens to create global notifications. | ||
# examples would be notices about KBase downtime or events. | ||
admins=wjriehl,scanon,kkeller,mmdrake | ||
|
||
# fake user name for the global feed. Should be something that's not a valid | ||
# user name. | ||
global-feed=_global_ |
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
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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import logging | ||
|
||
|
||
def get_log(name): | ||
return logging.getLogger(__name__) | ||
|
||
|
||
def log(name, msg, *args, level=logging.INFO): | ||
logging.getLogger(__name__).log(level, msg, *args) | ||
|
||
|
||
def log_error(name, error): | ||
log(name, "Exception: " + str(error) + error, level=logging.ERROR) |
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
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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from typing import List | ||
from ..base import ActivityStorage | ||
from .connection import get_feeds_collection | ||
from feeds.exceptions import ( | ||
ActivityStorageError | ||
) | ||
from pymongo import PyMongoError | ||
|
||
|
||
class MongoActivityStorage(ActivityStorage): | ||
def add_to_storage(self, activity, target_users: List[str]): | ||
""" | ||
Adds a single activity to the MongoDB. | ||
Returns None if successful. | ||
Raises an ActivityStorageError if it fails. | ||
""" | ||
coll = get_feeds_collection() | ||
act_doc = { | ||
"act_id": activity.id, | ||
"actor": activity.actor, | ||
"verb": activity.verb.id, | ||
"object": activity.object, | ||
"target": activity.target, | ||
"source": activity.source, | ||
"level": activity.level.id, | ||
"users": target_users, | ||
"unseen": target_users, | ||
"created": activity.time, | ||
"context": activity.context | ||
} | ||
try: | ||
coll.insert_one(act_doc) | ||
except PyMongoError as e: | ||
raise ActivityStorageError("Failed to store activity: " + str(e)) | ||
|
||
def get_from_storage(self, activity_ids): | ||
pass | ||
|
||
def remove_from_storage(self, activity_ids): | ||
raise NotImplementedError() | ||
|
||
def change_seen_mark(self, act_id: str, user: str, seen: bool): | ||
""" | ||
:param act_id: activity id | ||
:user: user id | ||
:seen: whether or not it's been seen. Boolean. | ||
""" | ||
raise NotImplementedError() |
Oops, something went wrong.