-
Notifications
You must be signed in to change notification settings - Fork 23
/
persistent_config.go
78 lines (62 loc) · 1.96 KB
/
persistent_config.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package operations
import (
"context"
"time"
"github.com/alcionai/clues"
"github.com/alcionai/corso/src/internal/common/crash"
"github.com/alcionai/corso/src/internal/events"
"github.com/alcionai/corso/src/internal/kopia"
"github.com/alcionai/corso/src/internal/stats"
"github.com/alcionai/corso/src/pkg/control"
"github.com/alcionai/corso/src/pkg/control/repository"
"github.com/alcionai/corso/src/pkg/count"
)
// PersistentConfig wraps an operation that deals with repo configuration.
type PersistentConfigOperation struct {
operation
Results PersistentConfigResults
configOpts repository.PersistentConfig
}
// PersistentConfigResults aggregate the details of the results of the operation.
type PersistentConfigResults struct {
stats.StartAndEndTime
}
// NewPersistentConfigOperation constructs and validates an operation to change
// various persistent config parameters like the minimum epoch duration for the
// kopia index.
func NewPersistentConfigOperation(
ctx context.Context,
opts control.Options,
kw *kopia.Wrapper,
configOpts repository.PersistentConfig,
bus events.Eventer,
) (PersistentConfigOperation, error) {
op := PersistentConfigOperation{
operation: newOperation(opts, bus, count.New(), kw, nil),
configOpts: configOpts,
}
// Don't run validation because we don't populate the model store.
return op, nil
}
func (op *PersistentConfigOperation) Run(ctx context.Context) (err error) {
defer func() {
if crErr := crash.Recovery(ctx, recover(), "persistent_config"); crErr != nil {
err = crErr
}
}()
// TODO(ashmrtn): Send telemetry?
return op.do(ctx)
}
func (op *PersistentConfigOperation) do(ctx context.Context) error {
op.Results.StartedAt = time.Now()
defer func() {
op.Results.CompletedAt = time.Now()
}()
err := op.operation.kopia.UpdatePersistentConfig(ctx, op.configOpts)
if err != nil {
op.Status = Failed
return clues.Wrap(err, "running update persistent config operation")
}
op.Status = Completed
return nil
}