`app` isn't set globally, and cherrypy.request isn't available from the cronjob stuff. Also add some debugging stuff because sending mails from the cronjob was throwing exceptions: I think it's in the weekly updates, but I haven't debugged it yet.
authorbsmedberg@pistons.dreamhost.com
Tue, 01 Dec 2009 11:47:43 -0800
changeset 18 de7c999d38d7
parent 17 f72ba24d7162
child 19 5710c4c527cc
push id16
push userbsmedberg@mozilla.com
push dateWed, 02 Dec 2009 20:27:53 +0000
`app` isn't set globally, and cherrypy.request isn't available from the cronjob stuff. Also add some debugging stuff because sending mails from the cronjob was throwing exceptions: I think it's in the weekly updates, but I haven't debugged it yet.
weeklyupdates/mail.py
weeklyupdates/main.py
--- a/weeklyupdates/mail.py
+++ b/weeklyupdates/mail.py
@@ -20,42 +20,47 @@ def sendmails(messages, fromaddress=None
     if smtpuser is not None:
         session.login(smtpuser, smtppass)
 
     for message in messages:
         if fromaddress is None:
             fromaddress = message['From']
         if recipientlist is None:
             recipientlist = [message['To']]
-        session.sendmail(fromaddress, recipientlist, message.as_string())
+        try:
+            session.sendmail(fromaddress, recipientlist, message.as_string())
+        except AttributeError, e:
+            print e
+            try:
+                print "Exception sending mail from %r to %r" % (fromaddress, recipientlist)
+            except:
+                pass
     session.quit()
 
 def sendpost(fromaddress, tolist, recipientlist, post):
     subject = "Status Update: %s on %s" % (post.username, post.postdate.isoformat())
 
     message = email.mime.multipart.MIMEMultipart('alternative')
     message['To'] = ', '.join(tolist)
     message['From'] = fromaddress
     message['Subject'] = subject
-    message['List-Id'] = app.config['weeklyupdates'].get('listid',
-                           '<weekly-updates.mozilla.com>')
+    message['List-Id'] = '<weekly-updates.mozilla.com>'
 
     html, text = rendermail('message.xhtml', subject, post=post)
     message.attach(email.mime.text.MIMEText(text, 'plain', 'UTF-8'))
     message.attach(email.mime.text.MIMEText(html, 'html', 'UTF-8'))
 
     sendmails([message], fromaddress, recipientlist)
 
 def getdigest(to, subject, posts):
     message = email.mime.multipart.MIMEMultipart('alternative')
     message['To'] = to
     message['From'] = _genericfrom
     message['Subject'] = subject
-    message['List-Id'] = app.config['weeklyupdates'].get('listid',
-                           '<weekly-updates.mozilla.com>')
+    message['List-Id'] = '<weekly-updates.mozilla.com>'
 
     html, text = rendermail('messagedigest.xhtml', subject, posts=posts)
     message.attach(email.mime.text.MIMEText(text, 'plain', 'UTF-8'))
     message.attach(email.mime.text.MIMEText(html, 'html', 'UTF-8'))
 
     return message
 
 def getnags(cur):
@@ -63,39 +68,43 @@ def getnags(cur):
         nag = """This is a friendly reminder from the Mozilla Status Board. """
         if lastpostdate is None:
             nag += "You have never made a post! "
         else:
             nag += "Your last post was %s. " % lastpostdate.isoformat()
 
         nag += "Please try to post weekly to keep other informed of your work."
 
+        print "Sending nag to %s <%s>" % (username, usermail)
+
         message = email.mime.text.MIMEText(nag, 'plain', 'UTF-8')
         message['To'] = usermail
         message['From'] = _genericfrom
         message['Subject'] = "Please post a status report"
-        message['List-Id'] = app.config['weeklyupdates'].get('listid',
-                               '<weekly-updates.mozilla.com>')
+        message['List-Id'] = '<weekly-updates.mozilla.com>'
         yield message
 
 def getdaily(cur):
     yesterday = util.today() - datetime.timedelta(1)
 
     for username, email, posts in model.iter_daily(cur, yesterday):
         if len(posts):
+            print "Sending daily update to %s <%s>" % (username, email)
             yield getdigest(email,
                             "Status Updates for %s" % yesterday.isoformat(),
                             posts)
 
 def getweekly(cur):
     yesterday = util.today() - datetime.timedelta(1)
     lastweek = util.today() - datetime.timedelta(7)
 
     for username, email, posts in model.iter_weekly(cur, lastweek, yesterday):
         if len(posts):
+            print "Sending weekly update to %s <%s>" % (username, email)
+
             subject = "Status Updates for %s through %s" % \
                 (lastweek.isoformat(), yesterday.isoformat()),
             yield getdigest(email, subject, posts)
 
 def sendtodaysmail(app):
     db = app.connectionpool().connectfn()
     cur = db.cursor()
 
--- a/weeklyupdates/main.py
+++ b/weeklyupdates/main.py
@@ -156,17 +156,17 @@ class Root(object):
 
         return render('user.xhtml', username=username, projects=projects,
                       teamposts=teamposts, userposts=userposts)
 
     @model.requires_db
     def userposts(self, username):
         posts = model.get_all_userposts(username)
         if not len(posts):
-            raise cherry.HTTPError(404, "No posts found")
+            raise cherrypy.HTTPError(404, "No posts found")
 
         return render('userposts.xhtml', username=username, posts=posts)
 
     @model.requires_db
     def userpostsfeed(self, username):
         feedposts = model.get_user_feedposts(username)
 
         return renderatom(feedposts=feedposts,