]> Cypherpunks repositories - gostls13.git/commitdiff
misc/dashboard/codereview: send mail immediately, and fill in time.Time fields.
authorDavid Symonds <dsymonds@golang.org>
Tue, 1 May 2012 01:33:25 +0000 (11:33 +1000)
committerDavid Symonds <dsymonds@golang.org>
Tue, 1 May 2012 01:33:25 +0000 (11:33 +1000)
If we delay the mail sending, we can't send as the current user.
If we don't fill in the time.Time fields, datastore.Put will fail
because the zero time.Time value is out of its range.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/6136053

misc/dashboard/codereview/dashboard/cl.go
misc/dashboard/codereview/dashboard/mail.go

index a77028994c98d805b419d55e11cb002789b8095f..bafef439bdbcd31fd94e0b0426e762f768010249 100644 (file)
@@ -16,7 +16,6 @@ import (
 
        "appengine"
        "appengine/datastore"
-       "appengine/delay"
        "appengine/mail"
        "appengine/taskqueue"
        "appengine/urlfetch"
@@ -105,8 +104,6 @@ func (cl *CL) ModifiedAgo() string {
        return "just now"
 }
 
-var sendMailLater = delay.Func("send-mail", mail.Send)
-
 func handleAssign(w http.ResponseWriter, r *http.Request) {
        c := appengine.NewContext(r)
 
@@ -196,7 +193,9 @@ func handleAssign(w http.ResponseWriter, r *http.Request) {
                                }
                                // TODO(dsymonds): Use cl.LastMessageID as the In-Reply-To header
                                // when the appengine/mail package supports that.
-                               sendMailLater.Call(c, msg)
+                               if err := mail.Send(c, msg); err != nil {
+                                       c.Errorf("mail.Send: %v", err)
+                               }
                        }
                }
        }
index a4bf1ac3e27691ab252f3a113008269a9227d7bc..7d910784434d2131108cb0df6fbf7044eadeb63f 100644 (file)
@@ -45,6 +45,12 @@ func handleMail(w http.ResponseWriter, r *http.Request) {
                if err != nil && err != datastore.ErrNoSuchEntity {
                        return err
                }
+               if err == datastore.ErrNoSuchEntity {
+                       // Must set sentinel values for time.Time fields
+                       // if this is a new entity.
+                       cl.Created = time.Unix(0, 0)
+                       cl.Modified = time.Unix(0, 0)
+               }
                cl.LastMessageID = msg.Header.Get("Message-ID")
                _, err = datastore.Put(c, key, cl)
                return err