Merge lp:~ev/oops-repository/whoopsie-daisy into lp:oops-repository

Proposed by Evan on 2012-01-10
Status: Merged
Merged at revision: 11
Proposed branch: lp:~ev/oops-repository/whoopsie-daisy
Merge into: lp:oops-repository
Diff against target: 77 lines (+22/-8)
2 files modified
oopsrepository/config.py (+2/-1)
oopsrepository/oopses.py (+20/-7)
To merge this branch: bzr merge lp:~ev/oops-repository/whoopsie-daisy
Reviewer Review Type Date Requested Status
Robert Collins 2012-01-10 Pending
Review via email: mp+88035@code.launchpad.net
To post a comment you must log in.
13. By Evan on 2012-01-10

Make OOPS_HOST an envar for consistency.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'oopsrepository/config.py'
2--- oopsrepository/config.py 2011-02-26 09:30:53 +0000
3+++ oopsrepository/config.py 2012-01-10 11:43:23 +0000
4@@ -10,7 +10,8 @@
5
6 def get_config():
7 """Get a dict of the config variables controlling oopsrepository."""
8- result = dict(keyspace=os.environ.get('OOPS_KEYSPACE'))
9+ result = dict(keyspace=os.environ.get('OOPS_KEYSPACE'),
10+ host=os.environ.get('OOPS_HOST'))
11 if not result['keyspace']:
12 raise Exception('No keyspace set - set via OOPS_KEYSPACE')
13 return result
14
15=== modified file 'oopsrepository/oopses.py'
16--- oopsrepository/oopses.py 2011-04-03 11:14:12 +0000
17+++ oopsrepository/oopses.py 2012-01-10 11:43:23 +0000
18@@ -7,6 +7,7 @@
19 """basic operations on oopses in the db."""
20
21 import json
22+import bson
23 import time
24 import uuid
25
26@@ -19,7 +20,7 @@
27
28 def prune(config):
29 """Remove OOPSES that are over 30 days old."""
30- pool = pycassa.connect(config['keyspace'])
31+ pool = pycassa.connect(config['keyspace'], config['host'])
32 dayoops_cf = pycassa.ColumnFamily(pool, 'DayOOPS')
33 oops_cf = pycassa.ColumnFamily(pool, 'OOPS')
34 # Find days to prune
35@@ -53,17 +54,11 @@
36 map(batch.remove, days)
37 batch.send()
38
39-
40 def insert(config, oopsid, oops_json):
41 """Insert an OOPS into the system.
42
43 :return: The day which the oops was filed under.
44 """
45- pool = pycassa.connect(config['keyspace'])
46- dayoops_cf = pycassa.ColumnFamily(pool, 'DayOOPS')
47- oops_cf = pycassa.ColumnFamily(pool, 'OOPS')
48- day_key = time.strftime('%Y%m%d', time.gmtime())
49- now_uuid = uuid.uuid1()
50 # make sure the oops report is a json dict, and break out each key to a
51 # separate column. For now, rather than worrying about typed column values
52 # we just coerce them all to strings.
53@@ -72,6 +67,24 @@
54 insert_dict = {}
55 for key, value in oops_dict.items():
56 insert_dict[key] = json.dumps(value)
57+ return _insert(config, oopsid, insert_dict)
58+
59+def insert_bson(config, oopsid, oops_bson):
60+ """Insert an OOPS into the system.
61+
62+ :return: The day which the oops was filed under.
63+ """
64+ oops_dict = bson.BSON(oops_bson)
65+ insert_dict = oops_dict.to_dict()
66+ return _insert(config, oopsid, insert_dict)
67+
68+def _insert(config, oopsid, insert_dict):
69+ pool = pycassa.connect(config['keyspace'], config['host'])
70+ dayoops_cf = pycassa.ColumnFamily(pool, 'DayOOPS')
71+ oops_cf = pycassa.ColumnFamily(pool, 'OOPS')
72+ day_key = time.strftime('%Y%m%d', time.gmtime())
73+ now_uuid = uuid.uuid1()
74+
75 oops_cf.insert(oopsid, insert_dict)
76 dayoops_cf.insert(day_key, {now_uuid:oopsid})
77 return day_key

Subscribers

People subscribed via source and target branches

to all changes: