Exemple #1
0
func example() {
	var ctx context.Context

	// [START deleting_tasks]
	// Purge entire queue...
	err := taskqueue.Purge(ctx, "queue1")

	// Delete an individual task...
	t := &taskqueue.Task{Name: "foo"}
	err = taskqueue.Delete(ctx, t, "queue1")
	// [END deleting_tasks]
	_ = err
}
Exemple #2
0
func (t tqImpl) Purge(queueName string) error {
	return taskqueue.Purge(t.aeCtx, queueName)
}
Exemple #3
0
func (t tqImpl) Purge(queueName string) error {
	return taskqueue.Purge(t.Context, queueName)
}
Exemple #4
0
func handlerGceManager(w http.ResponseWriter, r *http.Request) {
	ctx := appengine.NewContext(r)

	client := &http.Client{
		Transport: &oauth2.Transport{
			Source: google.AppEngineTokenSource(ctx, compute.ComputeScope),
			Base:   &urlfetch.Transport{Context: ctx},
		},
	}
	s, err := compute.New(client)
	if err != nil {
		log.Errorf(ctx, "ERROR compute.New: %s", err)
		w.WriteHeader(500)
		return
	}
	is := compute.NewInstancesService(s)
	ilc := is.List("cp300demo1", "us-central1-b")
	il, err := ilc.Do()
	if err != nil {
		log.Errorf(ctx, "ERROR instances list: %s", err)
		w.WriteHeader(500)
		return
	}
	count := 0
	for _, item := range il.Items {
		log.Infof(ctx, "id = %s, name = %s, creationTimestamp = %s", item.Id, item.Name, item.CreationTimestamp)
		if strings.HasPrefix(item.Name, INSTANCE_NAME) {
			count++
		}
	}
	threshold := 3
	if count > threshold {
		log.Infof(ctx, "Create a new instance is canceled.")
		w.WriteHeader(200)
		return
	}

	qs, err := taskqueue.QueueStats(ctx, []string{"pull-queue"})
	if err != nil {
		log.Errorf(ctx, "ERROR get queue stats: %s", err)
		w.WriteHeader(500)
		return
	}
	if qs[0].Tasks < 1 {
		log.Infof(ctx, "gce-manager purge.")
		err = taskqueue.Purge(ctx, "gce-manager")
		if err != nil {
			log.Warningf(ctx, "missing gce-manager purge. err = %s", err)
		}
	}
	if count > qs[0].Tasks {
		log.Infof(ctx, "instance count %d > task count %d", count, qs[0].Tasks)
		w.WriteHeader(200)
		return
	}

	threshold = math.MinInt32(threshold, qs[0].Tasks)
	names := make([]string, 0)
	for i := count; i < threshold; i++ {
		name, err := createInstance(ctx, is)
		if err != nil {
			time.Sleep(3 * time.Second)
		}
		names = append(names, name)
	}

	w.WriteHeader(200)
	fmt.Fprint(w, names)
}