Exemplo n.º 1
0
func (c *Calculation) Remove(collection string) error {
	session := db.GetSession()
	defer session.Close()
	col := session.DB("").C(collection)
	log.Printf("Removing this guy from %v:\n%v\n", collection, c)
	return col.RemoveId(c.Id)
}
Exemplo n.º 2
0
// Insert a calculation to a specified collection
func (c *Calculation) Insert(collection string) error {
	session := db.GetSession()
	defer session.Close()

	col := session.DB("").C(collection)
	log.Printf("Inserting into %v\n%v\n", collection, c)
	err := col.Insert(c)
	return err
}
Exemplo n.º 3
0
// Get a calculation from mongo by _id
func Get(id string) (c *Calculation, err error) {
	session := db.GetSession()
	defer session.Close()

	col := session.DB("").C(db.Complete)

	err = col.FindId(bson.ObjectIdHex(id)).One(&c)
	return c, err
}
Exemplo n.º 4
0
// Get recent calcuations where error is empty
func GetRecent(n int) Calculations {
	session := db.GetSession()
	defer session.Close()

	c := session.DB("").C(db.Complete)

	result := Calculations{}
	err := c.Find(nil).Sort("-time").Limit(n).All(&result)
	if err != nil {
		log.Printf("Got an error finding recent calculations: %v", err.Error())
	}
	return result
}
Exemplo n.º 5
0
func GetNext() *Calculation {
	session := db.GetSession()
	defer session.Close()
	col := session.DB("").C(db.Queue)

	change := mgo.Change{
		Update:    bson.M{"$set": bson.M{"processing": true}},
		ReturnNew: true,
	}
	var result Calculation
	info, err := col.Find(bson.M{"processing": false}).Apply(change, &result)
	log.Printf("ChangeInfo:\n%v\n", info)
	if err != nil {
		log.Printf("Error in GetNext: %v", err)
	}
	log.Printf("Found: %v\n", result)
	// If we found anything
	if result.Processing {
		return &result
	}
	return &Calculation{}
}