mirror of
https://github.com/lzh-1625/go_process_manager.git
synced 2025-10-06 08:27:03 +08:00
rename service
This commit is contained in:
37
internal/app/logic/log_handler.go
Normal file
37
internal/app/logic/log_handler.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/lzh-1625/go_process_manager/config"
|
||||
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
||||
"github.com/lzh-1625/go_process_manager/log"
|
||||
|
||||
"github.com/panjf2000/ants/v2"
|
||||
)
|
||||
|
||||
type loghandler struct {
|
||||
antsPool *ants.Pool
|
||||
}
|
||||
|
||||
var (
|
||||
Loghandler = new(loghandler)
|
||||
)
|
||||
|
||||
func InitLogHandle() {
|
||||
Loghandler.antsPool, _ = ants.NewPool(config.CF.LogHandlerPoolSize, ants.WithNonblocking(true), ants.WithExpiryDuration(3*time.Second), ants.WithPanicHandler(func(i interface{}) {
|
||||
log.Logger.Error("es消息储存失败")
|
||||
}))
|
||||
}
|
||||
|
||||
func (l *loghandler) AddLog(data model.ProcessLog) {
|
||||
if err := l.antsPool.Submit(func() {
|
||||
LogLogicImpl.Insert(data.Log, data.Name, data.Using, data.Time)
|
||||
}); err != nil {
|
||||
log.Logger.Warnw("协程池添加任务失败", "err", err, "当前运行数量", l.antsPool.Running())
|
||||
}
|
||||
}
|
||||
|
||||
func (l *loghandler) GetRunning() int {
|
||||
return l.antsPool.Running()
|
||||
}
|
Reference in New Issue
Block a user