func (m *Model) refresh(query mongo.Query) error { err := query.One(&m.doc) if err == mgo.ErrNotFound { return errors.NotFoundf("model") } return err }
func (st *State) migrationFromQuery(query mongo.Query) (ModelMigration, error) { var doc modelMigDoc err := query.One(&doc) if err == mgo.ErrNotFound { return nil, errors.NotFoundf("migration") } else if err != nil { return nil, errors.Annotate(err, "migration lookup failed") } statusColl, closer := st.getCollection(migrationsStatusC) defer closer() var statusDoc modelMigStatusDoc err = statusColl.FindId(doc.Id).One(&statusDoc) if err == mgo.ErrNotFound { return nil, errors.NotFoundf("migration status") } else if err != nil { return nil, errors.Annotate(err, "migration status lookup failed") } return &modelMigration{ doc: doc, statusDoc: statusDoc, st: st, }, nil }
func statusHistory(args *statusHistoryArgs) ([]status.StatusInfo, error) { filter := args.filter if err := args.filter.Validate(); err != nil { return nil, errors.Annotate(err, "validating arguments") } statusHistory, closer := args.st.getCollection(statusesHistoryC) defer closer() var ( docs []historicalStatusDoc query mongo.Query ) baseQuery := bson.M{"globalkey": args.globalKey} if filter.Delta != nil { delta := *filter.Delta // TODO(perrito666) 2016-05-02 lp:1558657 updated := time.Now().Add(-delta) baseQuery = bson.M{"updated": bson.M{"$gt": updated.UnixNano()}, "globalkey": args.globalKey} } if filter.Date != nil { baseQuery = bson.M{"updated": bson.M{"$gt": filter.Date.UnixNano()}, "globalkey": args.globalKey} } query = statusHistory.Find(baseQuery).Sort("-updated") if filter.Size > 0 { query = query.Limit(filter.Size) } err := query.All(&docs) if err == mgo.ErrNotFound { return []status.StatusInfo{}, errors.NotFoundf("status history") } else if err != nil { return []status.StatusInfo{}, errors.Annotatef(err, "cannot get status history") } results := make([]status.StatusInfo, len(docs)) for i, doc := range docs { results[i] = status.StatusInfo{ Status: doc.Status, Message: doc.StatusInfo, Data: utils.UnescapeKeys(doc.StatusData), Since: unixNanoToTime(doc.Updated), } } return results, nil }