Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
e664fc3a
Commit
e664fc3a
authored
Feb 15, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add command to change keep time for reqlog objects
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
2600a029
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
25 deletions
+39
-25
commands/reqlog.go
commands/reqlog.go
+19
-24
core/commands/active.go
core/commands/active.go
+20
-1
No files found.
commands/reqlog.go
View file @
e664fc3a
...
@@ -44,6 +44,7 @@ type ReqLog struct {
...
@@ -44,6 +44,7 @@ type ReqLog struct {
Requests
[]
*
ReqLogEntry
Requests
[]
*
ReqLogEntry
nextID
int
nextID
int
lock
sync
.
Mutex
lock
sync
.
Mutex
keep
time
.
Duration
}
}
func
(
rl
*
ReqLog
)
Add
(
req
Request
)
*
ReqLogEntry
{
func
(
rl
*
ReqLog
)
Add
(
req
Request
)
*
ReqLogEntry
{
...
@@ -69,43 +70,37 @@ func (rl *ReqLog) Add(req Request) *ReqLogEntry {
...
@@ -69,43 +70,37 @@ func (rl *ReqLog) Add(req Request) *ReqLogEntry {
func
(
rl
*
ReqLog
)
ClearInactive
()
{
func
(
rl
*
ReqLog
)
ClearInactive
()
{
rl
.
lock
.
Lock
()
rl
.
lock
.
Lock
()
defer
rl
.
lock
.
Unlock
()
defer
rl
.
lock
.
Unlock
()
i
:=
0
k
:=
rl
.
keep
for
j
:=
0
;
j
<
len
(
rl
.
Requests
);
j
++
{
rl
.
keep
=
0
if
rl
.
Requests
[
j
]
.
Active
{
rl
.
cleanup
()
rl
.
Requests
[
i
]
=
rl
.
Requests
[
j
]
rl
.
keep
=
k
i
++
}
}
rl
.
Requests
=
rl
.
Requests
[
:
i
]
}
}
func
(
rl
*
ReqLog
)
maybeCleanup
()
{
func
(
rl
*
ReqLog
)
maybeCleanup
()
{
// only do it every so often or it might
// only do it every so often or it might
// become a perf issue
// become a perf issue
if
len
(
rl
.
Requests
)
==
0
{
if
len
(
rl
.
Requests
)
%
10
==
0
{
rl
.
cleanup
()
rl
.
cleanup
()
}
}
}
}
func
(
rl
*
ReqLog
)
cleanup
()
{
func
(
rl
*
ReqLog
)
cleanup
()
{
var
i
int
i
:=
0
// drop all logs at are inactive and more than an hour old
now
:=
time
.
Now
()
for
;
i
<
len
(
rl
.
Requests
);
i
++
{
for
j
:=
0
;
j
<
len
(
rl
.
Requests
);
j
++
{
req
:=
rl
.
Requests
[
i
]
rj
:=
rl
.
Requests
[
j
]
if
req
.
Active
||
req
.
EndTime
.
Add
(
time
.
Hour
/
2
)
.
After
(
time
.
Now
())
{
if
rj
.
Active
||
rl
.
Requests
[
j
]
.
EndTime
.
Add
(
rl
.
keep
)
.
After
(
now
)
{
break
rl
.
Requests
[
i
]
=
rl
.
Requests
[
j
]
}
}
if
i
>
0
{
var
j
int
for
i
<
len
(
rl
.
Requests
)
{
rl
.
Requests
[
j
]
=
rl
.
Requests
[
i
]
j
++
i
++
i
++
}
}
rl
.
Requests
=
rl
.
Requests
[
:
len
(
rl
.
Requests
)
-
i
]
}
}
rl
.
Requests
=
rl
.
Requests
[
:
i
]
}
func
(
rl
*
ReqLog
)
SetKeepTime
(
t
time
.
Duration
)
{
rl
.
lock
.
Lock
()
defer
rl
.
lock
.
Unlock
()
rl
.
keep
=
t
}
}
// Report generates a copy of all the entries in the requestlog
// Report generates a copy of all the entries in the requestlog
...
...
core/commands/active.go
View file @
e664fc3a
...
@@ -25,7 +25,8 @@ Lists running and recently run commands.
...
@@ -25,7 +25,8 @@ Lists running and recently run commands.
cmds
.
BoolOption
(
"v"
,
"verbose"
,
"print more verbose output"
),
cmds
.
BoolOption
(
"v"
,
"verbose"
,
"print more verbose output"
),
},
},
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
"clear"
:
clearInactiveCmd
,
"clear"
:
clearInactiveCmd
,
"set-time"
:
setRequestClearCmd
,
},
},
Marshalers
:
map
[
cmds
.
EncodingType
]
cmds
.
Marshaler
{
Marshalers
:
map
[
cmds
.
EncodingType
]
cmds
.
Marshaler
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
...
@@ -92,3 +93,21 @@ var clearInactiveCmd = &cmds.Command{
...
@@ -92,3 +93,21 @@ var clearInactiveCmd = &cmds.Command{
req
.
InvocContext
()
.
ReqLog
.
ClearInactive
()
req
.
InvocContext
()
.
ReqLog
.
ClearInactive
()
},
},
}
}
var
setRequestClearCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Set how long to keep inactive requests in the log"
,
},
Arguments
:
[]
cmds
.
Argument
{
cmds
.
StringArg
(
"time"
,
true
,
false
,
"time to keep inactive requests in log"
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
tval
,
err
:=
time
.
ParseDuration
(
req
.
Arguments
()[
0
])
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
req
.
InvocContext
()
.
ReqLog
.
SetKeepTime
(
tval
)
},
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment