Example #1
0
func TestTasks(t *testing.T) {

	c, err := NewContext(&Options{TaskQueues: []string{"testQueue"}})
	if err != nil {
		t.Fatalf("NewContext: %v", err)
	}
	defer c.Close()

	task := taskqueue.NewPOSTTask("/post", map[string][]string{})
	_, err = taskqueue.Add(c, task, "testQueue")
	if err != nil {
		t.Fatalf("Could not add task to queue")
	}
	stats, err := taskqueue.QueueStats(c, []string{"testQueue"}, 0) // fetch all of them
	if err != nil {
		t.Fatalf("Could not get taskqueue statistics")
	}
	t.Logf("TaskStatistics = %#v", stats)
	if len(stats) == 0 {
		t.Fatalf("Queue statistics are empty")
	} else if stats[0].Tasks != 1 {
		t.Fatalf("Could not find the task we just added")
	}

	err = taskqueue.Purge(c, "testQueue")
	if err != nil {
		t.Fatalf("Could not purge the queue")
	}
	stats, err = taskqueue.QueueStats(c, []string{"testQueue"}, 0) // fetch all of them
	if len(stats) == 0 {
		t.Fatalf("Queue statistics are empty")
	}
	if stats[0].Tasks != 0 {
		t.Fatalf("Purge command not successful")
	}

	tasks := []*taskqueue.Task{
		taskqueue.NewPOSTTask("/post1", map[string][]string{}),
		taskqueue.NewPOSTTask("/post2", map[string][]string{}),
	}
	_, err = taskqueue.AddMulti(c, tasks, "testQueue")
	if err != nil {
		t.Fatalf("Could not add bulk tasklist to queue")
	}
	stats, err = taskqueue.QueueStats(c, []string{"testQueue"}, 0) // fetch all of them
	if err != nil {
		t.Fatalf("Could not get taskqueue statistics")
	}
	if len(stats) == 0 {
		t.Fatalf("Could not find the tasks we just added")
	} else if stats[0].Tasks != 2 {
		t.Fatalf("Could not find the tasks we just added")
	}

}
func TaskRemove(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	name := mux.Vars(r)["name"]
	c.Debugf("remove task name = %s", name)

	if err := taskqueue.Purge(c, name); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	fmt.Fprintf(w, "remove task = %s", name)
}
Example #3
0
//function that starts the data checking, making sure only one instance of the data checker is running
func startDataChecking(r *http.Request) {
	//log.Print("startDataChecking")

	if LastCheckTime+TIMEINTERVALBETWEENCHECKS < time.UTC().Seconds() {
		c := appengine.NewContext(r)
		taskqueue.Purge(c, "") //clears any other running data checking tasks, if there are any

		t := taskqueue.NewPOSTTask("/keepDataUpToDate", nil) //creates a new task
		//t.Delay=1e7
		if _, err4 := taskqueue.Add(c, t, ""); err4 != nil { //runs the task
			log.Print("startDataChecking err4: %v", err4)
			return
		}
		//log.Print("startDatChecking end")
	}
}
func RSVPMeetupEvents(events []MeetupEvent, r *http.Request) string {
	c := appengine.NewContext(r)
	queuetasks := make([]*taskqueue.Task, 0)

	taskqueue.Purge(c, "futurersvp")

	for _, event := range events {
		t := ProcessEvent(event, r)
		if t != nil {
			queuetasks = append(queuetasks, t)
		}
	}

	taskqueue.AddMulti(c, queuetasks, "futurersvp")

	str := fmt.Sprintf("Total Number of Meetups processed: %d\n", len(events))
	str = str + fmt.Sprintf("Total Number of future Meetups queued: %d\n", len(queuetasks))
	log.Print(str)

	return str
}
Example #5
0
//function that checks data periodically and schedules itself again
func keepDataUpToDate(w http.ResponseWriter, r *http.Request) {
	//log.Print("keepDataUpToDate")

	//check if the function isn't called too often
	//for example by calling this function directly by something other than the program itself
	if LastCheckTime+TIMEINTERVALBETWEENCHECKS/2 < time.UTC().Seconds() {
		c := appengine.NewContext(r)
		LastCheckTime = time.UTC().Seconds() //logs the last check time

		checkData(c) //checks the data

		taskqueue.Purge(c, "") //clears any other running data checking tasks, if there are any

		t := taskqueue.NewPOSTTask("/keepDataUpToDate", nil) //creates a new task
		t.Delay = TIMEINTERVALBETWEENCHECKS                  //schedules it once an hour
		if _, err4 := taskqueue.Add(c, t, ""); err4 != nil {
			log.Print("startDataChecking err4: %v", err4)
			return
		}
		//log.Print("keepDataUpToDate end")
	}
}