-
Notifications
You must be signed in to change notification settings - Fork 4
/
release.go
51 lines (39 loc) · 1.14 KB
/
release.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package store
import (
"context"
"fmt"
log "github.com/Sirupsen/logrus"
"cloud.google.com/go/datastore"
pb "github.com/datacol-io/datacol/api/models"
)
func (g *DSBackend) ReleaseList(app string, limit int64) (pb.Releases, error) {
q := datastore.NewQuery(releaseKind).Namespace(g.DeploymentName).Filter("app = ", app)
if limit > 0 {
q = q.Limit(int(limit))
}
var rs pb.Releases
_, err := g.datastore().GetAll(context.Background(), q, &rs)
return rs, err
}
func (g *DSBackend) ReleaseDelete(app, id string) error {
ctx, key := g.nestedKey(releaseKind, id)
return g.datastore().Delete(ctx, key)
}
func (g *DSBackend) ReleaseSave(b *pb.Release) error {
ctx, key := g.nestedKey(releaseKind, b.Id)
if _, err := g.datastore().Put(ctx, key, b); err != nil {
return fmt.Errorf("saving release err: %v", err)
}
return nil
}
func (g *DSBackend) ReleaseCount(app string) (version int64) {
q := datastore.NewQuery(releaseKind).
Namespace(g.DeploymentName).
Filter("app = ", app)
total, err := g.datastore().Count(context.Background(), q)
if err != nil {
log.Warnf("fetching release total: %v", err)
}
version = int64(total)
return
}