Created
January 2, 2014 13:16
-
-
Save nl5887/8219016 to your computer and use it in GitHub Desktop.
Go Google Appengine RunInBackground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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