Exemple #1
0
func (api *APIHandler) someWInfo(request *restful.Request, response *restful.Response) {
	ref := request.PathParameter("ref")
	id := graph.TaskID(ref)

	// Get task
	t, err := api.todo.GetTask(id)
	if err != nil {
		response.AddHeader("Content-Type", "text/plain")
		response.WriteErrorString(http.StatusInternalServerError, err.Error())
		return
	}

	// Get available deps
	tasks, err := api.todo.GetUnblockedDependencies(id)
	if err != nil {
		response.AddHeader("Content-Type", "text/plain")
		response.WriteErrorString(http.StatusInternalServerError, err.Error())
		return
	}

	// Write back response
	response.WriteEntity(json.Response{
		Info:  t,
		Tasks: tasks.Values(),
	})
}
Exemple #2
0
func MakeTestTasksN(height, width, connectivity int) graph.Tasks {
	t := make(graph.Tasks)

	levels := make([][]*graph.Task, height)
	for i := range levels {
		levels[i] = make([]*graph.Task, width)
		for j := range levels[i] {
			task := &graph.Task{
				Id:           graph.TaskID(strconv.FormatInt(rand.Int63(), 10)),
				Start:        rand.Int63(),
				End:          rand.Int63(),
				Completed:    rand.Int()%2 == 0,
				Dependencies: graph.MakeTaskIDSet(),
			}
			t[task.Id] = task
			levels[i][j] = task
		}
	}

	for depth, level := range levels[:height-1] {
		for _, task := range level {
			connections := rand.Int31n(int32(connectivity))
			for i := 0; i < int(connections); i++ {
				row, col := rand.Int31n(int32(height-depth-1)), rand.Int31n(int32(width))
				task.Dependencies.Add(levels[depth+int(row)+1][col].Id)
			}
		}
	}
	return t
}
Exemple #3
0
func toTaskIDMap(s []string) map[graph.TaskID]struct{} {
	m := make(map[graph.TaskID]struct{})
	for _, id := range s {
		m[graph.TaskID(id)] = struct{}{}
	}
	return m
}
Exemple #4
0
func (t Task) ToGraphTask() graph.Task {
	return graph.Task{
		Id:           graph.TaskID(t.Id),
		Start:        t.Start,
		End:          t.End,
		Completed:    t.Completed,
		Dependencies: toTaskIDMap(t.Dependencies),
		Description:  t.Description,
		Weight:       t.Weight,
	}
}
Exemple #5
0
func (api *APIHandler) finish(request *restful.Request, response *restful.Response) {
	vs := request.Request.URL.Query()
	ref := graph.TaskID(request.PathParameter("ref"))
	obliterate := len(vs["obliterate"]) > 0 && vs["obliterate"][0] == "true"
	if len(vs["verify"]) > 0 && vs["verify"][0] == "true" {
		api.todo.MarkCompletedVerify(ref, obliterate)
	} else if len(vs["verify"]) > 0 && vs["recursive"][0] == "true" {
		api.todo.MarkCompletedRecursive(ref, obliterate)
	} else {
		api.todo.MarkCompleted(ref, obliterate)
	}
}
Exemple #6
0
func (api *APIHandler) update(request *restful.Request, response *restful.Response) {
	ref := request.PathParameter("ref")
	id := graph.TaskID(ref) // TODO: Resolve ref once we have aliases and classes.
	t, err := api.todo.GetTask(id)
	if err != nil {
		response.AddHeader("Content-Type", "text/plain")
		response.WriteErrorString(http.StatusInternalServerError, err.Error())
		return
	}
	request.ReadEntity(&t)

	// Set everything to whatever the new values are
	for dep, _ := range t.Dependencies {
		api.todo.AddDependency(id, dep)
	}

	// err = api.todo.SetEndTime(id, t.End)
	// if err != nil {
	//     response.AddHeader("Content-Type", "text/plain")
	//     response.WriteErrorString(http.StatusInternalServerError, err.Error())
	//     return
	// }

	// err = api.todo.SetStartTime(id, t.Start)
	// if err != nil {
	//     response.AddHeader("Content-Type", "text/plain")
	//     response.WriteErrorString(http.StatusInternalServerError, err.Error())
	//     return
	// }

	err = api.todo.SetDescription(id, t.Description)
	if err != nil {
		response.AddHeader("Content-Type", "text/plain")
		response.WriteErrorString(http.StatusInternalServerError, err.Error())
		return
	}

	// api.todo.SetRunCmd(id, runcmd)
	// api.todo.SetWeight(id, weight)

	tasks, err := api.todo.GetUnblockedDependencies(id)
	if err != nil {
		response.AddHeader("Content-Type", "text/plain")
		response.WriteErrorString(http.StatusInternalServerError, err.Error())
		return
	}

	response.WriteEntity(json.Response{
		Info:  t,
		Tasks: tasks.Values(),
	})
}
Exemple #7
0
func (l local) AddTask(t graph.Task) (graph.TaskID, error) {
	for id := range t.Dependencies {
		if _, ok := l.tasks[id]; !ok {
			return graph.TaskID(""), newInvalidRefError(id)
		}
	}
	// Make sure the caller can't
	// muck with our data later
	t = t.Copy()
	t.Id = graph.GenerateID()
	l.tasks[t.Id] = &t
	return t.Id, nil
}
Exemple #8
0
	Long:  "Add a new task to the graph, specifying its properties (aliases, classes, times, etc.).",
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("something (ran add)")
		m, err := getMiddleman(file, true)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Unable to acquire resource to add new task: %v", err)
			return
		}
		defer cleanupCall(m)
		t := graph.MakeTask()
		t.SetStartTime(parse(start))
		t.SetEndTime(parse(end))
		t.Weight = float64(weight)
		t.Description = args[0]
		if dep != "" {
			t.Dependencies.Add(graph.TaskID(dep))
		}
		_, err = m.AddTask(t)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Unable to add new task to resource: %v", err)
			return
		}

		// Point `alias' to `taskid' if needed
		if alias != "" {
			// TODO: Implement aliases
		}

		// Add task to `class' if needed
		if class != "" {
			// TODO: Implement classes