Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
孙龙
/
go-api-behavior
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7cdc868d
authored
Feb 25, 2020
by
孙龙
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
init
parent
133cfdd8
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
service/behavior/apiMsgService/LogSink.go
service/behavior/apiMsgService/LogSink.go
View file @
7cdc868d
...
...
@@ -45,10 +45,12 @@ func (logSink *LogSink) writeLoop() {
var
(
log
*
DataParams
logBatch
*
LogBatch
// 当前的批次
commitTimer
*
time
.
Timer
//
commitTimer *time.Timer
//timeoutBatch *LogBatch // 超时批次
)
t
:=
time
.
NewTimer
(
time
.
Second
*
20
)
defer
t
.
Stop
()
for
{
select
{
case
log
=
<-
logSink
.
logChan
:
...
...
@@ -59,17 +61,14 @@ func (logSink *LogSink) writeLoop() {
// 把新日志追加到批次中
logBatch
.
Logs
=
append
(
logBatch
.
Logs
,
log
)
// 如果批次满了, 就立即发送
if
len
(
logBatch
.
Logs
)
>=
10
{
if
len
(
logBatch
.
Logs
)
>=
10
0
{
// 发送日志
logSink
.
saveLogs
(
logBatch
)
// 清空logBatch
logBatch
=
nil
// 取消定时器
//commitTimer.Stop()
}
case
<-
t
ime
.
NewTimer
(
1
*
time
.
Second
)
.
C
:
case
<-
t
.
C
:
if
logBatch
==
nil
{
logBatch
=
&
LogBatch
{}
}
...
...
@@ -77,6 +76,7 @@ func (logSink *LogSink) writeLoop() {
fmt
.
Println
(
len
(
logBatch
.
Logs
))
logSink
.
saveLogs
(
logBatch
)
logBatch
=
nil
t
.
Reset
(
time
.
Second
*
20
)
}
...
...
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