command to clear inactive requests from request log
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Feb 4, 2016 at 10:04 UTC
1e1c89c2a86772e272a45ffcb6a54c45ed9c180f
2 files changed
+26
-1
commands/reqlog.go
+14
-1
@@ -66,6 +66,19 @@ func (rl *ReqLog) Add(req Request) *ReqLogEntry {
66
return rle
67
}
68
69
+func (rl *ReqLog) ClearInactive() {
70
+ rl.lock.Lock()
71
+ defer rl.lock.Unlock()
72
+ i := 0
73
+ for j := 0; j < len(rl.Requests); j++ {
74
+ if rl.Requests[j].Active {
75
+ rl.Requests[i] = rl.Requests[j]
76
+ i++
77
+ }
78
+ }
79
+ rl.Requests = rl.Requests[:i]
80
+}
81
+
82
func (rl *ReqLog) maybeCleanup() {
83
// only do it every so often or it might
84
// become a perf issue
@@ -79,7 +92,7 @@ func (rl *ReqLog) cleanup() {
92
// drop all logs at are inactive and more than an hour old
93
for ; i < len(rl.Requests); i++ {
94
req := rl.Requests[i]
82
- if req.Active || req.EndTime.Add(time.Hour).After(time.Now()) {
95
+ if req.Active || req.EndTime.Add(time.Hour/2).After(time.Now()) {
96
break
97
}
98
}
core/commands/active.go
+12
@@ -24,6 +24,9 @@ Lists running and recently run commands.
24
Options: []cmds.Option{
25
cmds.BoolOption("v", "verbose", "print more verbose output"),
26
},
27
+ Subcommands: map[string]*cmds.Command{
28
+ "clear": clearInactiveCmd,
29
+ },
30
Marshalers: map[cmds.EncodingType]cmds.Marshaler{
31
cmds.Text: func(res cmds.Response) (io.Reader, error) {
32
out, ok := res.Output().(*[]*cmds.ReqLogEntry)
@@ -80,3 +83,12 @@ Lists running and recently run commands.
83
},
84
Type: []*cmds.ReqLogEntry{},
85
}
86
+
87
+var clearInactiveCmd = &cmds.Command{
88
+ Helptext: cmds.HelpText{
89
+ Tagline: "Clear inactive requests from the log",
90
+ },
91
+ Run: func(req cmds.Request, res cmds.Response) {
92
+ req.InvocContext().ReqLog.ClearInactive()
93
+ },
94
+}