Created
April 2, 2014 20:47
-
-
Save teepark/9942821 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# vim: fileencoding=utf8:et:sw=4:ts=8:sts=4 | |
from datahog import context, table, entity, prop, storage, pool | |
from django.conf import settings | |
from sentry.nodestore import base | |
BASE = 1 | |
context.set_context(BASE, table.ENTITY) | |
BLOB = 2 | |
context.set_context(BLOB, table.PROPERTY, { | |
'base_ctx': BASE, | |
'storage': storage.SERIAL, | |
}) | |
class NodeStorage(base.NodeStorage): | |
def __init__(self, *args, **kwargs): | |
super(NodeStorage, self).__init__(*args, **kwargs) | |
self._dbpool = None | |
@property | |
def pool(self): | |
if self._dbpool is None: | |
p = self._dbpool = pool.GreenhouseConnPool( | |
settings.SENTRY_NODESTORE_OPTIONS) | |
p.start() | |
if not p.wait_ready(2.0): | |
raise Exception("postgres connection timeout") | |
return self._dbpool | |
def delete(self, id): | |
entity.remove(self.pool, long(id), BASE) | |
def get(self, id): | |
return prop.get(self.pool, id, BLOB)['value'] | |
def set(self, id, data): | |
return prop.set(self.pool, id, BLOB, data) | |
def generate_id(self): | |
return entity.create(self.pool, BASE)['guid'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment