func (self *MongoInterface) getTask(id string) agro_pb.Task { result := make(map[string]interface{}) self.db.C("task").Find(bson.M{"_id": id}).One(&result) out := agro_pb.Task{} agro.MapToProto(result, &out, true) return out }
func (self *MongoInterface) getJob(jobID string) *agro_pb.Job { result := make(map[string]interface{}) err := self.db.C("job").Find(bson.M{"_id": jobID}).One(&result) if err != nil { return nil } out := &agro_pb.Job{} agro.MapToProto(result, out, true) return out }
func (self *MongoInterface) GetTaskJobs(taskID string) chan agro_pb.Job { out := make(chan agro_pb.Job) go func() { var iter = self.db.C("job").Find(bson.M{"task_id": taskID}).Iter() result := make(map[string]interface{}) for iter.Next(&result) { pout := agro_pb.Job{} agro.MapToProto(result, &pout, true) out <- pout } close(out) }() return out }
func (self *MongoInterface) SearchWorkers(tags *agro_pb.TagArray, stream agro_pb.Scheduler_SearchWorkersServer) error { var iter *mgo.Iter = nil if len(tags.Tags) > 0 { iter = self.db.C("worker").Find(bson.M{"tags": bson.M{"$all": tags.Tags}}).Iter() } else { iter = self.db.C("worker").Find(nil).Iter() } result := make(map[string]interface{}) for iter.Next(&result) { out := agro_pb.WorkerInfo{} agro.MapToProto(result, &out, true) stream.Send(&out) } return nil }
func (self *MongoInterface) JobQuery(state *agro_pb.State, max int) chan agro_pb.Job { out := make(chan agro_pb.Job) count := 0 go func() { i := self.db.C("job").Find(bson.M{"state": state.String()}).Iter() result := make(map[string]interface{}) for i.Next(&result) { pout := agro_pb.Job{} agro.MapToProto(result, &pout, true) out <- pout count += 1 if max > 0 && count >= max { break } } close(out) }() return out }
func (self *MongoInterface) TaskQuery(states []agro_pb.State) chan agro_pb.Task { out := make(chan agro_pb.Task) go func() { qSet := make([]string, len(states)) for _, s := range states { qSet = append(qSet, s.String()) } i := self.db.C("task").Find( bson.M{ "state": bson.M{"$in": qSet}, }).Iter() result := make(map[string]interface{}) for i.Next(&result) { pout := agro_pb.Task{} agro.MapToProto(result, &pout, true) out <- pout } close(out) }() return out }