Permalink
Browse files

Make the support structure a little more robust

  • Loading branch information...
1 parent dcecd8b commit ab82e18428320423530fc8e2ba41363aadc8dec2 @nibrahim nibrahim committed Jun 21, 2011
View
No changes.
View
@@ -32,7 +32,6 @@ def create_stats_client():
else:
return False
except Exception:
- #TBD : Log stats error here
return False
def put(key, value):
@@ -8,16 +8,19 @@
class InvalidCase(KeyError): pass
+class DatabaseConnectionError(Exception): pass
@web.memoize
def get_admin_database():
admin_db = config.get("admin", {}).get("admin_db",None)
if admin_db:
return couchdb.Database(admin_db)
+ else:
+ raise DatabaseConnectionError("No admin_db specified in config")
class Support(object):
- def __init__(self, db = None): #TBD : handle database failures
+ def __init__(self, db = None):
if db:
self.db = db
else:
@@ -32,7 +32,7 @@ def wrapped(*largs, **kargs):
d = dict(largs = json.dumps(largs),
kargs = json.dumps(kargs),
command = fn.__name__,
- started_at = datetime.datetime.now(), #TBD. This is not when we started.
+ started_at = datetime.datetime.now(),
log = log,
result = ret)
logging.root.removeHandler(h)
@@ -9,16 +9,22 @@
class cases(object):
def GET(self):
+ if not support_db:
+ return render_template("admin/cases", None, True)
cases = support_db.get_all_cases()
return render_template("admin/cases", cases)
class case(object):
def GET(self, caseid):
+ if not support_db:
+ return render_template("admin/cases", None, True)
case = support_db.get_case(caseid)
date_pretty_printer = lambda x: x.strftime("%B %d, %Y")
return render_template("admin/case", case, date_pretty_printer)
def POST(self, caseid):
+ if not support_db:
+ return render_template("admin/cases", None, True)
case = support_db.get_case(caseid)
form = web.input()
action = form.get("button","")
@@ -37,7 +43,10 @@ def POST_sendreply(self, form, case):
case.change_status("replied", user.get_email())
if email_to:
print "Send email to %s"%email_to
- #TBD
+ import pdb;pdb.set_trace()
+ # web.sendmail(email_to, config.report_spam_address, msg.subject, str(msg))
+ # print config.report_spam_address
+
def POST_update(self, form, case):
@@ -59,13 +68,11 @@ def POST_closecase(self, form, case):
case.add_worklog_entry(by = by,
text = text)
-
-
-
-
-
def setup():
global support_db
- support_db = support.Support()
+ try:
+ support_db = support.Support()
+ except support.DatabaseConnectionError:
+ support_db = None
@@ -83,7 +83,7 @@ class task(object):
def GET(self, taskid):
try:
db = connect_to_taskdb()
- q = "SELECT * FROM celery_taskmeta WHERE task_id = '%(taskid)s'"%dict(taskid = taskid) #TBD (VERY BAD!!)
+ q = "SELECT * FROM celery_taskmeta WHERE task_id = '%(taskid)s'"%dict(taskid = taskid)
ret = db.query(q)
if not ret:
return "No such task"
@@ -1,40 +1,55 @@
-$def with (cases)
+$def with (cases, error = False)
<div id="contentHead">
<h1>$_("Admin Center")</h1>
- <div class="small">
- <a href="/admin/reload/">Reload Templates</a>
- | <a href="/admin/block">Block IPs</a>
- | <a href="/admin/loans">Loans</a>
- | <a href="/admin/status">Services</a>
- | <a href="/admin/support">Support</a>
- </div>
+ $:render_template("admin/menu", "/admin")
</div>
<div id="contentBody">
+<style type="text/css">
+table.support {
+ font-family: Lucida, "Lucida Sans";
+ font-size: 0.75em;
+ }
-<h1>Help Cases</h1>
-<p>Filter: 3,617 <strong>Total</strong> | 28 <a href="#filter for new">New</a> | 45 <a href="#filter by replied">Replied</a> | 3,546 <a href="#filter by closed">Closed</a></p>
-
-<table class = "support" border="0" cellspacing="0" cellpadding="10">
- <tr>
- <th><a href="#SORT-BY">Created</a></th>
- <th><a href="#SORT-BY">#</a></th>
- <th><a href="#SORT-BY">Subject</a></th>
- <th><a href="#SORT-BY">User</a></th>
- <th><a href="#SORT-BY">Assigned to</a></th>
+table.support th {
+ font-weight: bold;
+ }
+table.support th, table.support td {
+ border-bottom: 1px solid #ddd;
+ vertical-align:top;
+ padding: 5pt;
+ }
+table.support pre.hidden {
+ display: none;
+ }
- <th><a href="#SORT-BY">Last Update</a></th>
- <th><a href="#SORT-BY">Status</a></th>
- </tr>
- $for case in cases:
- <tr>
- <td>$datestr(case.created)</td>
- <td>$case.caseid</td>
- <td><a href="/admin/support/case/$(case.caseid)">$case.subject</a></td>
- <td>$case.creator_name</td>
- <td>$case.assignee</td>
- <td>$datestr(case.last_modified)</td>
- <td>$case.status</td>
- </tr>
-</table>
-</div>
+</style>
+<h1>Help Cases</h1>
+$if error:
+ <p>Couldn't connect to support database</p>
+$else:
+ <p>Filter: 3,617 <strong>Total</strong> | 28 <a href="#filter for new">New</a> | 45 <a href="#filter by replied">Replied</a> | 3,546 <a href="#filter by closed">Closed</a></p>
+
+ <table class = "support" border="0" cellspacing="0" cellpadding="10">
+ <tr>
+ <th><a href="#SORT-BY">Created</a></th>
+ <th><a href="#SORT-BY">#</a></th>
+ <th><a href="#SORT-BY">Subject</a></th>
+ <th><a href="#SORT-BY">User</a></th>
+ <th><a href="#SORT-BY">Assigned to</a></th>
+
+ <th><a href="#SORT-BY">Last Update</a></th>
+ <th><a href="#SORT-BY">Status</a></th>
+ </tr>
+ $for case in cases:
+ <tr>
+ <td>$datestr(case.created)</td>
+ <td>$case.caseid</td>
+ <td><a href="/admin/support/case/$(case.caseid)">$case.subject</a></td>
+ <td>$case.creator_name</td>
+ <td>$case.assignee</td>
+ <td>$datestr(case.last_modified)</td>
+ <td>$case.status</td>
+ </tr>
+ </table>
+ </div>
@@ -13,6 +13,8 @@
class contact(delegate.page):
def GET(self):
+ if not support_db:
+ return "The Openlibrary support system is currently offline. Please try again later."
i = web.input(path=None)
email = context.user and context.user.email
return render_template("support", email=email, url=i.path)
@@ -38,6 +40,8 @@ def POST_old(self):
return render_template("support", done = True)
def POST_new(self):
+ if not support_db:
+ return "Couldn't initialise connection to support database"
form = web.input()
email = form.get("email", "")
topic = form.get("topic", "")
@@ -51,11 +55,15 @@ def POST_new(self):
subject = topic,
description = description,
url = url,
- assignee = "mary@archive.org") # TBD. This has to be dynamic
+ assignee = "mary@archive.org")
return render_template("support", done = True)
def setup():
global support_db
- support_db = S.Support()
+ try:
+ support_db = S.Support()
+ except S.DatabaseConnectionError:
+ support_db = None
+
View
@@ -0,0 +1,30 @@
+import time
+from openlibrary.core.task import oltask
+import logging
+
+logger1 = logging.getLogger("Bunyan 1")
+logger1.setLevel(logging.DEBUG)
+h = logging.StreamHandler()
+h.setLevel(logging.DEBUG)
+f = logging.Formatter("%(levelname)s : %(filename)s : %(name)s : %(message)s")
+h.setFormatter(f)
+logger1.addHandler(h)
+
+
+@oltask
+def baz(a, b):
+ time.sleep(10)
+ logger1.debug("Hello")
+ logger1.warn("Hello")
+ logger1.critical("Dead")
+ logger1.info("""All source code published here is available under the terms of the GNU Affero General Public License, version 3. Please see http://gplv3.fsf.org/ for more information.""")
+ return a + b
+
+
+
+for i in range(50):
+ print "Hello", baz.delay(2, 2)
+
+
+
+

0 comments on commit ab82e18

Please sign in to comment.