-
Notifications
You must be signed in to change notification settings - Fork 14
/
reboot_dequeue.go
58 lines (47 loc) · 1.05 KB
/
reboot_dequeue.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
package op
import (
"context"
"strconv"
"github.com/cybozu-go/cke"
"github.com/cybozu-go/cke/metrics"
)
type rebootDequeueOp struct {
index int64
finished bool
}
// RebootDequeueOp returns an Operator to dequeue a reboot entry.
func RebootDequeueOp(index int64) cke.Operator {
return &rebootDequeueOp{
index: index,
}
}
func (o *rebootDequeueOp) Name() string {
return "reboot-dequeue"
}
func (o *rebootDequeueOp) NextCommand() cke.Commander {
if o.finished {
return nil
}
o.finished = true
return rebootDequeueCommand{index: o.index}
}
func (o *rebootDequeueOp) Targets() []string {
return nil
}
type rebootDequeueCommand struct {
index int64
}
func (c rebootDequeueCommand) Run(ctx context.Context, inf cke.Infrastructure, leaderKey string) error {
err := inf.Storage().DeleteRebootsEntry(ctx, leaderKey, c.index)
if err != nil {
return err
}
metrics.DecrementReboot()
return nil
}
func (c rebootDequeueCommand) Command() cke.Command {
return cke.Command{
Name: "rebootDequeueCommand",
Target: strconv.FormatInt(c.index, 10),
}
}