Skip to content

Instantly share code, notes, and snippets.

@teepark
Created April 2, 2014 20:47
Show Gist options
  • Save teepark/9942821 to your computer and use it in GitHub Desktop.
Save teepark/9942821 to your computer and use it in GitHub Desktop.
# 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