Beispiel #1
0
func (self *Webserver) GetTask(w http.ResponseWriter, r *http.Request) {
	params := mux.Vars(r)
	taskId := params["id"]
	task, _ := self.client.GetTask(context.Background(), &agro_pb.IDQuery{Ids: []string{taskId}})
	data := agro.ProtoToMap(task, false)

	status_client, _ := self.client.GetTaskStatus(context.Background(), &agro_pb.IDQuery{Ids: []string{taskId}})
	status, _ := status_client.Recv()
	status_data := agro.ProtoToMap(status, false)
	data["status"] = status_data

	t, _ := json.Marshal(data)
	w.Write(t)
}
Beispiel #2
0
func (self *MongoInterface) WorkerPing(context context.Context, worker *agro_pb.WorkerInfo) (*agro_pb.WorkerInfo, error) {
	t := time.Now().Unix()
	worker.LastPing = &t
	w := agro.ProtoToMap(worker, true)
	self.db.C("worker").UpsertId(worker.Id, w)
	return worker, nil
}
Beispiel #3
0
func (self *Webserver) GetJob(w http.ResponseWriter, r *http.Request) {
	params := mux.Vars(r)
	jobId := params["id"]
	job, _ := self.client.GetJob(context.Background(), &agro_pb.IDQuery{Ids: []string{jobId}})
	data := agro.ProtoToMap(job, false)
	t, _ := json.Marshal(data)
	w.Write(t)
}
Beispiel #4
0
func (self *MongoInterface) AddTask(ctx context.Context, task *agro_pb.Task) (*agro_pb.TaskStatus, error) {
	task.State = agro_pb.State_WAITING.Enum()
	e := agro.ProtoToMap(task, true)
	err := self.db.C("task").Insert(e)
	s := agro_pb.State_OK
	if err != nil {
		s = agro_pb.State_ERROR
	}
	o := &agro_pb.TaskStatus{
		Id:    task.Id,
		State: &s,
	}
	return o, err
}
Beispiel #5
0
func (self *Webserver) Workers(w http.ResponseWriter, r *http.Request) {
	results, _ := self.client.SearchWorkers(context.Background(), &agro_pb.TagArray{})
	out := make(chan map[string]interface{})
	go func() {
		for done := false; !done; {
			task, err := results.Recv()
			if err == io.EOF {
				done = true
			} else {
				m := agro.ProtoToMap(task, false)
				out <- m
			}
		}
		close(out)
	}()
	stream2array(w, out)
}
Beispiel #6
0
func (self *MongoInterface) GetJobToRun(request *agro_pb.JobRequest, stream agro_pb.Scheduler_GetJobToRunServer) error {
	w := agro.ProtoToMap(request.Worker, true)
	self.db.C("worker").UpsertId(request.Worker.Id, w)
	for id, job := range self.jobCache {
		self.UpdateJobState(context.Background(),
			&agro_pb.UpdateStateRequest{
				Id:       job.Id,
				State:    agro_pb.State_QUEUED.Enum(),
				WorkerId: request.Worker.Id,
			},
		)

		delete(self.jobCache, id)
		log.Printf("Sending job: %s", *job.Id)
		if err := stream.Send(job); err != nil {
			fmt.Printf("Error: %s", err)
			return err
		}
		return nil
	}
	log.Printf("No Jobs Found")
	go self.workScan()
	return nil
}
Beispiel #7
0
func (self *MongoInterface) AddJob(job *agro_pb.Job) error {
	e := agro.ProtoToMap(job, true)
	return self.db.C("job").Insert(e)
}