Skip to content

Commit d82ceac

Browse files
committed
fix: 防止并发
1 parent 006255e commit d82ceac

File tree

8 files changed

+36
-21
lines changed

8 files changed

+36
-21
lines changed

type_exception.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ var ExceptionSplit = "github.com/sirupsen/logrus/"
3737

3838
func (b *Exception) Handler(entry *logrus.Entry) (*entries, []tag) {
3939
strStack := entry.Data["stack"].(string)
40-
return b.ToSave(strStack, entry.Message)
40+
41+
return (*b).ToSave(strStack, entry.Message)
4142
}
4243

4344
func (b *Exception) ToSave(strStack, msg string) (*entries, []tag) {

type_job.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type Job struct {
2323
Hostname string `json:"hostname"`
2424
}
2525

26-
func (b *Job) Boot() {
26+
func (j *Job) Boot() {
2727
if app2.IsDebug() && app.HasBean("queue") {
2828
server := app.GetBean("queue").(*servers.Queue)
2929
server.AddMiddleware(func(job constraint.Job, next func(constraint.Job)) {
@@ -45,11 +45,13 @@ func (b *Job) Boot() {
4545
}
4646
}
4747

48-
func (b *Job) BindType() string {
48+
func (j *Job) BindType() string {
4949
return "job"
5050
}
5151

52-
func (b *Job) Handler(entry *logrus.Entry) (*entries, []tag) {
52+
func (j *Job) Handler(entry *logrus.Entry) (*entries, []tag) {
53+
b := *j
54+
5355
b.Name = entry.Message
5456
b.Data = entry.Data["data"]
5557
b.Status = entry.Data["status"].(string)

type_log.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ type Log struct {
1414
Context map[string]interface{} `json:"context"`
1515
}
1616

17-
func (b *Log) BindType() string {
17+
func (l *Log) BindType() string {
1818
return "log"
1919
}
2020

21-
func (b *Log) Handler(entry *logrus.Entry) (*entries, []tag) {
21+
func (l *Log) Handler(entry *logrus.Entry) (*entries, []tag) {
22+
b := *l
23+
2224
if entry.Level <= logrus.ErrorLevel {
2325
hasError = true
2426
defer func() {

type_query.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,24 @@ type Query struct {
2323
Hostname string `json:"hostname"`
2424
}
2525

26-
func (b *Query) Init() {
27-
b.Hostname, _ = os.Hostname()
26+
func (q *Query) Init() {
27+
q.Hostname, _ = os.Hostname()
2828
}
2929

30-
func (b *Query) BindType() string {
30+
func (q *Query) BindType() string {
3131
return "query"
3232
}
3333

3434
// QuerySplit 切割标识, 这个标识以后的代码才是业务的
3535
var QuerySplit = "/app/entity/"
3636

37-
func (b *Query) Handler(entry *logrus.Entry) (*entries, []tag) {
37+
func (q *Query) Handler(entry *logrus.Entry) (*entries, []tag) {
3838
if strings.Index(entry.Message, "telescope_") != -1 {
3939
return nil, nil
4040
}
41-
b.File = ""
41+
42+
b := *q
43+
4244
// 根据模型目录 /app/entity/ 定位业务调用
4345
stack := string(debug.Stack())
4446
arr := strings.Split(string(stack), "\n")

type_redis.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ type Redis struct {
1616
Hostname string `json:"hostname"`
1717
}
1818

19-
func (b *Redis) BindType() string {
19+
func (r *Redis) BindType() string {
2020
return "redis"
2121
}
2222

2323
// RedisSplit 切割标识, 这个标识以后的代码才是业务的
2424
var RedisSplit = "github.com/sirupsen/logrus/"
2525

26-
func (b *Redis) Handler(entry *logrus.Entry) (*entries, []tag) {
26+
func (r *Redis) Handler(entry *logrus.Entry) (*entries, []tag) {
27+
b := *r
28+
2729
file, line := GetStackCallFile(string(debug.Stack()), RedisSplit)
2830

2931
b.Connection = file + ":" + line

type_request.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ type Request struct {
2727
Hostname string `json:"hostname,omitempty"`
2828
}
2929

30-
func (b *Request) Init() {
31-
b.Hostname, _ = os.Hostname()
30+
func (req *Request) Init() {
31+
req.Hostname, _ = os.Hostname()
3232
}
3333

34-
func (b *Request) BindType() string {
34+
func (req *Request) BindType() string {
3535
return "request"
3636
}
3737

38-
func (b *Request) Handler(entry *logrus.Entry) (*entries, []tag) {
38+
func (req *Request) Handler(entry *logrus.Entry) (*entries, []tag) {
39+
b := *req
40+
3941
b.Payload = make(map[string]interface{})
4042

4143
uuId := uuid.NewV4().String()

type_schedule.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ type Schedule struct {
1717
Hostname string `json:"hostname"`
1818
}
1919

20-
func (b *Schedule) BindType() string {
20+
func (s *Schedule) BindType() string {
2121
return "schedule"
2222
}
2323

24-
func (b *Schedule) Handler(entry *logrus.Entry) (*entries, []tag) {
24+
func (s *Schedule) Handler(entry *logrus.Entry) (*entries, []tag) {
25+
b := *s
26+
2527
b.Command = entry.Message
2628
return &entries{
2729
Uuid: uuid.NewV4().String(),

type_tcp.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ type Tcp struct {
2424
Hostname string `json:"hostname,omitempty"`
2525
}
2626

27-
func (b *Tcp) BindType() string {
27+
func (c *Tcp) BindType() string {
2828
return "tcp"
2929
}
3030

3131
// Handler
3232
// logrus.WithFields(logrus.Fields{"type": "tcp","read": raw,"tags": []string{str}}).Debug(tpc_route)
33-
func (b *Tcp) Handler(entry *logrus.Entry) (*entries, []tag) {
33+
func (c *Tcp) Handler(entry *logrus.Entry) (*entries, []tag) {
34+
b := *c
35+
3436
ip, ok := entry.Data["ip"]
3537
if ok {
3638
b.IpAddress = ip.(string)

0 commit comments

Comments
 (0)