Exemple #1
0
func BackendStart(c mpg.Context, w http.ResponseWriter, r *http.Request) {
	return
	const sz = 100
	ic := 0
	var f func(appengine.Context)
	var cs string
	f = func(c appengine.Context) {
		gn := goon.FromContext(c)
		c.Errorf("ic: %d", ic)
		wg := sync.WaitGroup{}
		wg.Add(sz)
		var j int64
		q := datastore.NewQuery("F").KeysOnly()
		if cs != "" {
			if cur, err := datastore.DecodeCursor(cs); err == nil {
				q = q.Start(cur)
				c.Errorf("cur start: %v", cur)
			}
		}
		it := q.Run(c)
		for j = 0; j < sz; j++ {
			k, err := it.Next(nil)
			c.Errorf("%v: %v, %v", j, k, err)
			if err != nil {
				c.Criticalf("err: %v", err)
				return
			}

			go func(k *datastore.Key) {
				f := Feed{Url: k.StringID()}
				if err := gn.Get(&f); err == nil {
					f.Subscribe(c)
				}

				wg.Done()
			}(k)
		}
		cur, err := it.Cursor()
		if err == nil {
			cs = cur.String()
		}
		wg.Wait()
		ic++
		runtime.RunInBackground(c, f)
	}
	runtime.RunInBackground(c, f)
}
Exemple #2
0
func BackendStart(c mpg.Context, w http.ResponseWriter, r *http.Request) {
	const sz = 100
	ic := 0
	gn := goon.FromContext(c)
	fk := gn.Key(&Feed{Url: "a"})
	q := datastore.NewQuery("F").Filter("__key__ <", fk).Order("__key__").KeysOnly().Limit(1)
	keys, _ := q.GetAll(c, nil)
	if len(keys) == 0 {
		return
	}
	c.Errorf("start: %v", keys[0])
	startid := keys[0].IntID() / sz

	var f func(appengine.Context)
	f = func(c appengine.Context) {
		c.Errorf("new request: %d", ic)
		t1 := time.Now()
		wg := sync.WaitGroup{}
		wg.Add(sz)
		var j int64
		for j = 0; j < sz; j++ {
			go func(j int64) {
				k := datastore.NewKey(c, "F", "", startid*sz+j, nil)
				c.Infof("del: %v", k)
				if err := datastore.Delete(c, k); err != nil {
					c.Errorf("delete err: %v", err.Error())
				}
				wg.Done()
			}(j)
		}
		wg.Wait()
		t2 := time.Now()
		c.Infof("%v, %v, %v", t1, t2, t2.Sub(t1))
		ic++
		startid++
		runtime.RunInBackground(c, f)
	}
	runtime.RunInBackground(c, f)
}