Commits

Miki Tebeka committed 9aafa69

Use dealy instead of taskqueue

Comments (0)

Files changed (1)

shortie/shortie.go

 import (
 	"appengine"
 	"appengine/datastore"
+	"appengine/delay"
 	"appengine/memcache"
 	"appengine/user"
-	"appengine/taskqueue"
 	"fmt"
 	"http"
 	"os"
 	}, nil)
 }
 
+var delayedInc = delay.Func("hits", incHits)
+
 // userURLs return a list of user urls, ordered by time (max 1000).
 func userURLs(ctx appengine.Context, user string) ([]*URL, os.Error) {
 	query := datastore.NewQuery(urlKind).
 		if err == datastore.Done {
 			break
 		}
+		// FIXME: Handle NEED_INDEX (when index is built)
 		if err != nil {
 			return nil, err
 		}
 	}
 
 	// Offload hit counter update to a task
-	task := taskqueue.NewPOSTTask(hitWorkerPath, map[string][]string{"path": {path}})
-	if _, err := taskqueue.Add(ctx, task, ""); err != nil {
-		return
-	}
+	delayedInc.Call(ctx, path)
 
 	http.Redirect(w, r, longURL, http.StatusTemporaryRedirect)
 }