Skip to content

Instantly share code, notes, and snippets.

@nl5887
Created January 2, 2014 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nl5887/8219016 to your computer and use it in GitHub Desktop.
Save nl5887/8219016 to your computer and use it in GitHub Desktop.
Go Google Appengine RunInBackground
package harvest
import (
_ "encoding/base64"
_ "fmt"
"net/http"
"appengine"
"appengine/runtime"
_ "math"
)
func init() {
http.HandleFunc("/_ah/warmup", handleWarmup)
http.HandleFunc("/_ah/start", handleStart)
http.HandleFunc("/_ah/stop", handleStop)
}
func handleWarmup(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
c.Infof("Warming up.")
}
func handleStart(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
error := runtime.RunInBackground(c, runLoop)
c.Infof("error %s", error)
}
func runLoop(c appengine.Context) {
c.Infof("Running")
for {
time.Sleep(time.Millisecond * 2000)
}
return
}
func handleStop(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
c.Infof("Stopping.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment