-
Notifications
You must be signed in to change notification settings - Fork 567
/
renewer.go
40 lines (34 loc) · 1.04 KB
/
renewer.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
package chunk
import (
"context"
"github.com/pachyderm/pachyderm/v2/src/internal/meters"
"github.com/pachyderm/pachyderm/v2/src/internal/pctx"
"time"
"github.com/pachyderm/pachyderm/v2/src/internal/errors"
"github.com/pachyderm/pachyderm/v2/src/internal/storage/renew"
"github.com/pachyderm/pachyderm/v2/src/internal/storage/track"
)
type Renewer struct {
ss *renew.StringSet
}
func NewRenewer(ctx context.Context, tr track.Tracker, name string, ttl time.Duration) *Renewer {
ctx = pctx.Child(ctx, "trackerRenewer", pctx.WithCounter("renewals", 0))
renewFunc := func(ctx context.Context, x string, ttl time.Duration) error {
_, err := tr.SetTTL(ctx, x, ttl)
if err != nil {
return errors.EnsureStack(err)
}
meters.Inc(ctx, "renewals", 1)
return nil
}
composeFunc := renew.NewTmpComposer(tr, name)
return &Renewer{
ss: renew.NewStringSet(ctx, ttl, renewFunc, composeFunc),
}
}
func (r *Renewer) Add(ctx context.Context, id ID) error {
return r.ss.Add(ctx, id.TrackerID())
}
func (r *Renewer) Close() error {
return r.ss.Close()
}