Пример #1
0
func assetReady(conn *db.MConn, path, bucket string, doc db.M) *db.Asset {
	var asset db.Asset

	if !strings.HasPrefix(path, "/") {
		path = "/" + path
	}

	conn.GetOne(db.ASSET, db.M{
		"path":   path,
		"bucket": bucket,
	}, &asset)

	if asset.Status != db.PENDING {
		log.WithField("asset", asset).Debugln("asset has an invalid state")
		return nil
	}

	err := conn.FindAndUpdate(db.ASSET, db.M{
		"path":   path,
		"bucket": bucket,
		"status": db.PENDING,
	}, doc, &asset)

	if err != nil {
		panic(err)
	}

	return &asset
}
Пример #2
0
func getAsset(conn *db.MConn, _id string) *db.Asset {
	var asset db.Asset
	err := conn.GetOne(db.ASSET, db.M{"_id": bson.ObjectIdHex(_id)}, &asset)
	if err != nil {
		panic(err)
	}

	return &asset
}