forked from farseer-go/fSchedule
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
51 lines (45 loc) · 1.22 KB
/
log.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
package fSchedule
import (
"encoding/json"
"github.com/farseer-go/collections"
"github.com/farseer-go/fs/core/eumLogLevel"
"github.com/farseer-go/fs/timingWheel"
"time"
)
// 任务日志
var logQueue chan logContent
type logReportDTO struct {
Logs []logContent
}
type logContent struct {
TaskId int64 // 主键
TaskGroupId int64 // 任务组ID
Name string // 实现Job的特性名称(客户端识别哪个实现类)
Ver int // 版本
LogLevel eumLogLevel.Enum
CreateAt int64
Content string
}
// enableReportLog 开启上传日志报告
func enableReportLog() {
for {
lstLogs := collections.NewList[logContent]()
tw := timingWheel.Add(1 * time.Second)
isContinue := true // 标记是否一直循环读取,当大于1秒,或者取出10条日志时,上传日志
for isContinue {
select {
case log := <-logQueue: // 从通道中取出日志数据
lstLogs.Add(log)
isContinue = lstLogs.Count() < 10
case <-tw.C: // 1秒时间到了
isContinue = false
}
}
if lstLogs.Count() > 0 {
dto := logReportDTO{Logs: lstLogs.ToArray()}
jsonByte, _ := json.Marshal(dto)
_, _ = defaultServer.logReport(jsonByte)
}
time.Sleep(500 * time.Millisecond)
}
}